Tag Archive | "DBGrid"

DBGrid com Imagens


Esta é uma dica muito simples mas que produz um efeito muito legal.

Já encontrei vários programas que, ao mostrar determinados dados em um DBGrid, pecavam pela falta de clareza. Por exemplo: Para mostrar se um cadastro estava ativo ou não, apresentava no grid uma coluna que era preenchida com Sim / Não.  Errado? Não. Mas você concorda que pode ficar melhor não é?

Então ai vai minha dica para aperfeiçoar suas aplicações:

1. Estou partindo do ponto em que você ja tem seu ClientDataSet vinculado a um DataSource o qual ja se encontra vinculado a um DBGrid. No exemplo o ClientDataSet se chama TabAux e o DBGrid se chama Grade.

2. Insira um TImageList no seu form e adicione duas imagens.

Você pode baixar as imagens clicando aqui

TImageList

3. No evento OnDrawColumnCell do seu DBGrid escreva o seguinte código:

if Column.Field=TabAuxATIVO then
begin

Grade.Canvas.FillRect(Rect);

// Desenha o Quadrado
ImageList1.Draw(Grade.Canvas,Rect.Left+10,Rect.Top+1,0);

// Desenha o check sobre o quadrado quando ativo = ‘S’
if TabAuxATIVO.Text=‘S’ then // Cadastro está ativo
ImageList1.Draw(Grade.Canvas,Rect.Left+10,Rect.Top+1,1);
end;

4. O Resultado ficará assim

DBGrid com Imagem

Espero que aproveite esta dica. Ela é simples, mas da um toque mais profissional para a sua aplicação.

Posted in DBExpress, Dicas, TCanvasComments (10)




Conectar-se

Delphi Fórum

PHVsPjxsaT48c3Ryb25nPndvb19hZHNfcm90YXRlPC9zdHJvbmc+IC0gdHJ1ZTwvbGk+PGxpPjxzdHJvbmc+d29vX2FkX2ltYWdlXzE8L3N0cm9uZz4gLSBodHRwOi8vd3d3Lndvb3RoZW1lcy5jb20vYWRzLzEyNXgxMjVhLmpwZzwvbGk+PGxpPjxzdHJvbmc+d29vX2FkX2ltYWdlXzI8L3N0cm9uZz4gLSBodHRwOi8vd3d3Lndvb3RoZW1lcy5jb20vYWRzLzEyNXgxMjViLmpwZzwvbGk+PGxpPjxzdHJvbmc+d29vX2FkX2ltYWdlXzM8L3N0cm9uZz4gLSBodHRwOi8vd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