Anderson Nunes
Anderson Nunes

Reputation: 191

Number of rows in DBCtrlGrid on Delphi

When I use DBCtrlGrid Delphi component, setting the RowCount property to 5, for example, it will always display 5 lines on the component, even if the table has only 3 records. I need to know how do I hide the additional lines and show only the lines that my table has records.

Upvotes: 1

Views: 1971

Answers (1)

MartynA
MartynA

Reputation: 30735

You can use the AfterScroll event of the dataset connected to the DBCtrlGrid to set its RowCount:

procedure TForm1.qApplsAfterScroll(DataSet: TDataSet);
begin
  DBCtrlGrid1.RowCount := DataSet.RecordCount;
end;

Be aware, though, that not all types of Delphi dataset return meaningful numbers for their RecordCounts. If yours doesn't, you'll need to do something like running a "SELECT COUNT(*) ..." query in the AfterScroll event to get the value you need to set RowCount to.

Btw, the main use of datasets' AfterScroll event is to allow you to do things like this, where some action needs to be taken when the dataset's cursor moves.

Upvotes: 2

Related Questions