Custom DB Grid with webservice data

0

I'm creating a simple system to test the operation of Delphi with WebService REST, the first test is a search of data in the database that in this case is working everything right, only that when the data is loaded in the DBGrid the visualization gets horrible , I would like to know if you can customize the display of this information by changing the name and size of the columns.

DBGrid:

Asyoucansee,itgetsverybadwiththesegiantfieldsforlittleinformationandthesecolumntitlesgetthenamethatcomesfromWS.

IusedtheRESTDebuggertooltodothisWScommunicationwiththeGrid.

    
asked by anonymous 05.02.2018 / 12:59

1 answer

2

In some event after the data is loaded (perhaps at the end of the Search button event), do a for (repeat loop) of the grid columns and check the dataset the size of the field (eg string (200)), then calculate the width of the column, for example 200 * 3 and you will have an approximate size appropriate to the size of the field.

for i:=0 to dbgrid.columns.count -1 do
begin
  dbgrid.columns[i].width := dbgrid.datasource.dataset.fieldbyname(dbgrid.columns[i].fieldname).size * 3
end;

Of course the above code can be improved, it's just an idea how to do it. You can also see the field type (integer, varchar and etc.) and change the multiplication value.

    
05.02.2018 / 16:59