0

I am trying to display data from database table into DBAdvGrid so that first column will show only checkbox, while other 3 columns will show label, description and image field from database table. I am using UniConnection, UniQuery, UniDatasource components to display data. I am setting UniConnection Database properties via code as I can give relative path of the database rather than full path. At object inspector it accepts only fiull path of database.

My code is as follows At FormCreate event

  filepath1 := ExtractFilePath(Application.ExeName);
  UniConnection1.Database := filepath1+'empdata.s3db';
  UniConnection1.Connected := True;
  UniQuery1.SQL.Text := 'Select '', label, description, image from emp';
  UniQuery1.Open;

  DBAdvGrid1.Columns[0].FieldName := '';
  DBAdvGrid1.Columns[2].FieldName := 'label';
  DBAdvGrid1.Columns[3].FieldName := 'description';
  DBAdvGrid1.Columns[4].FieldName := 'image';

The above code connect and display data successfully but problem is with displaying data at DBAdvGrid as I want first column to display only checkbox (no data from DB). At DBAdvGrid I cannot set field name of particular column through object inspector as it is connecting to the database through code with by extracting path.

I have set first column of DBAdvGrid editor type property to the edDataCheckBox so that it would display checkbox in first column but it is getting overlapped by label data, similarly at second column it is showing 'description' and at 3rd column image.

How to customize it via code so that it would show

1st column - No Data
2nd column - label
3rd column - description
4th column - image

What I am getting as

1st column - label overlapped with checkbox
2nd column - description
3rd column - image {MEMO}
4th column - 

How to sort out this problem ?

enter image description here

Ninad Avasare
  • 333
  • 2
  • 7
  • 20

1 Answers1

1

Here is the way that I draw a checkbox in a grid: the DrawColumnCell event has to be defined as follows

const
 IsChecked : array[0..1] of Integer =
             (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);

procedure TForm.DBAdvGrid1DrawColumnCell(Sender: TObject;
          const Rect: TRect; DataCol: Integer; Column: TColumn;
          State: TGridDrawState);
var
 DrawRect: TRect;

begin
 if column.Index = 1 then  
  begin
   DrawRect:= Rect;
   drawrect.left:= rect.left + 24;
   InflateRect (DrawRect, -1, -1);
   DBAdvGrid1.Canvas.FillRect (Rect);
   DrawFrameControl (DBAdvGrid1.Canvas.Handle, DrawRect, DFC_BUTTON,
                     ISChecked[Column.Field.AsInteger]);
  end
 else DBAdvGrid1.DefaultDrawColumnCell (Rect, DataCol, Column, State);
end;
No'am Newman
  • 6,395
  • 5
  • 38
  • 50
  • @Noám Newman , good answer found new method to put checkbox in the column. Actually I can put the checkboc in first column of the DBAdvGrid with the help of Editor property of the DBAdvGrid.Column[1].Editor := edDataCheckBox. The main problem I am facing here is with display of data in DBAdvGrid. As it is displaying checkbox also and label field data in same column. I've attached screenshot. – Ninad Avasare Nov 21 '13 at 14:22
  • Here actually it shows 'label' field data in 1st and 2nd column. – Ninad Avasare Nov 21 '13 at 14:27