1
votes

When you place a dbgrid on your form, it creates 2 rows by default (a title row which is fixed and a normal row which is not fixed) My question is if there is a way to remove this 2nd normal row at runtime (leaving only the fixed title row) unless there is actually data to populate the row and in that case it should be shown of course.

For example, if I run a query that returns 0 results when my form is created, I would like only to show the title row, but if the query returns a result show the title row and all the rows that contain data like normal.

Any help would be appreciated.

1
In case if your DBGrid have defined columns (Columns property) and DataSet assigned to the grid (through TDataSourse) is not active (Active property is False) DBGrid shows only one row, header. Another solution: procedure TForm1.SQLQuery1AfterOpen(DataSet: TDataSet); begin DBGrid1.Visible := not SQLQuery1.IsEmpty; end; - Abelisto

1 Answers

1
votes

No, this is not possible. You can see this yourself by dropping a TDBGrid on a new form, and not attaching any datasource to it. It always has at least one data row, even if there is no data to populate it, and at least one column. (It makes sense that this isn't possible; it is, after all, a grid.)

The closest you can get is to remove dgColLines and dgRowLines from the TDBGrid.Options, which still leaves you with a data row, but it's just not clearly visible.