[SOLVED] Prevent DBGrid to show empty row in case 0 records returned lazarus / 16-Databases ---------------------------------------------------------------------- Zvoni · 2025-10-17 12:19 OK, i'll bite. I have a Form with 4 DBGrids, each connected to its own SQLquery- Datasource. User clicks/selects a record on the first Grid, which executes a new Query on the Datasource of the Second grid and so on.... In case the second Datasource returns 0 records, it still shows me an "empty" line/row below the (fixed) row with Column-Titles. How can i avoid that empty line? I'd like the Grid to show just the (fixed) row with Column-Titles (each grid has defined Columns with titles, width etc.). I thought Clear/ClearRows was the answer, but that throws out the Row with the Columns-Titles, too. Any ideas? Logic implies it might not even be a "property" of the Grid, but something of the Dataset or Datasource, but i haven't found anything pointing in that direction ---------------------------------------------------------------------- LacaK · 2025-10-23 12:27 As far as I can say it is default behavior - if DataSet is empty there is still 1 empty row in TDBGrid (I guess that this one empty row allow you to start write there to be able to append new record). Can you try exclude from TDBGrid.Options: dgIndicator, dgEditing, dgAlwaysShowEditor whether something changed? ---------------------------------------------------------------------- Zvoni · 2025-10-23 12:44 Quote from: LacaK on October 23, 2025, 02:27:06 pmAs far as I can say it is default behavior - if DataSet is empty there is still 1 empty row in TDBGrid (I guess that this one empty row allow you to start write there to be able to append new record). Can you try exclude from TDBGrid.Options: dgIndicator, dgEditing, dgAlwaysShowEditor whether something changed? Thx for the answer. Hmmm.... will have to try that..... Otherwise it is as it is. It's just "cosmetic" ---------------------------------------------------------------------- Soner · 2025-10-24 20:27 The only solution is to disable the query. If you are using ZEOS components:   if ZQuery1.RecordCount=0 then ZQuery1.Active:=false; If you are using SQLDB:   if SQLQuery1.RowsAffected=0 then SQLQuery1.Active:=false; ---------------------------------------------------------------------- rvk · 2025-10-24 20:30 Quote from: Soner on October 24, 2025, 10:27:04 pmThe only solution is to disable the query. That will also remove any fields automatically defined in the dataset and grid. So the (fixed) row with Column-Titles don't show anymore. You should have to save it and create the grid columns statically. ---------------------------------------------------------------------- Soner · 2025-10-24 20:37 Quote from: rvk on October 24, 2025, 10:30:34 pmQuote from: Soner on October 24, 2025, 10:27:04 pmThe only solution is to disable the query. That will also remove any fields automatically defined in the dataset and grid. So the (fixed) row with Column-Titles don't show anymore. You should have to save it and create the grid columns statically. It is useless because there is still a blank line, possibly a Delphi compatibility issue. We should fix TDBGrid. ---------------------------------------------------------------------- rvk · 2025-10-24 20:43 Without an active dataset there are no fields and the tdbgrid can't fill the column titles so it's useless anyway to fix it like that. It's better to fix it with a valid empty dataset and remove the empty line. But only when there is no edit option because the empty line serves a purpose at this moment (being the current dataset pointer, even if the dataset is empty) and you need it for adding records in editing mode. ---------------------------------------------------------------------- Soner · 2025-10-24 21:19 I have the solution. You need to change the file lazarus/lcl/dbgrids.pas as shown in the image; look at the two lines marked in red. EDIT: I noticed that nothing is displayed if the result of the quer is only one data row. But the solution is in this function. ---------------------------------------------------------------------- Zvoni · 2025-10-25 12:00 Quote from: rvk on October 24, 2025, 10:43:20 pmWithout an active dataset there are no fields and the tdbgrid can't fill the column titles so it's useless anyway to fix it like that. It's better to fix it with a valid empty dataset and remove the empty line. But only when there is no edit option because the empty line serves a purpose at this moment (being the current dataset pointer, even if the dataset is empty) and you need it for adding records in editing mode. Rvk, not correct. I have TColums defined that connect to the fields of the dataset. And those have the titles. I‘m not using the field names ---------------------------------------------------------------------- rvk · 2025-10-25 12:27 Quote from: Zvoni on October 25, 2025, 02:00:16 pmRvk, not correct. I have TColums defined that connect to the fields of the dataset. And those have the titles. I‘m not using the field names Yes, those are statically assigned during design time. I was talking about the dynamically assigned columns from the dataset. Quote from: rvk on October 24, 2025, 10:30:34 pmQuote from: Soner on October 24, 2025, 10:27:04 pmThe only solution is to disable the query. That will also remove any fields automatically defined in the dataset and grid. So the (fixed) row with Column-Titles don't show anymore. You should have to save it and create the grid columns statically. I normally have my columns defined dynamically because of I change the SQL, the column change with it. ---------------------------------------------------------------------- Zvoni · 2025-10-27 07:50 OK, found it. Soner brought me on the right track with his Active:=False; In a Nutshell it boils down to If RS.RecordCount=0 Then RS.Close; ---------------------------------------------------------------------- rvk · 2025-10-27 07:56 Quote from: Zvoni on October 27, 2025, 08:50:00 amIn a Nutshell it boils down to If RS.RecordCount=0 Then RS.Close; Sure. If the columns of the grid are statically created during design time, this is a valid solution. Otherwise you loose the column definitions. But if it's works in your situation, it's a good solution for you. ---------------------------------------------------------------------- Zvoni · 2025-10-27 10:22 Quote from: rvk on October 27, 2025, 08:56:38 amQuote from: Zvoni on October 27, 2025, 08:50:00 amIn a Nutshell it boils down to If RS.RecordCount=0 Then RS.Close; Sure. If the columns of the grid are statically created during design time, this is a valid solution. Otherwise you loose the column definitions. But if it's works in your situation, it's a good solution for you. Yeah. Though i don't like to work with DB-bound Controls, i have to in this case. And since i'm used to define my Columns for e.g. StringGrid, i've adopted the same approach for DBGrid