MSiipola 0 Posted April 15, 2021 I'm using Embarcadero® Delphi 10.3 Version (update 3). I have a sqlite db connected to a TBGrid via TFDConnection, TDataSource and TFDTable. Connection and populating the grid is done in runtime. Example: begin CloseAllDB(); Journal_DBGrid.Visible := false; DBGrid.Visible := true; NamnTabell.Open(); DBSource.DataSet := NamnTabell; end; The data source (DBSource) is connected to different db's during execution, selected with different button. The problem is with the Caption of columns for the DBGrid object in the example. I have also an other grid 'Journal_DBGrid' which has it own TDataSource and db-table, but it has not the problem I'm describing below. I have opened and activated all components in order do be able to see the result during development. I can change the caption for different fields, and it displays correctly in the grid, but during runtime the column header shows the db fieldname and not the caption I want. Any ideas where the problem is? Share this post Link to post
Gary 18 Posted April 15, 2021 Not sure what you mean by "change caption for different fields". You can do this at design time by right click fdTable and open field editor, right click and add all fields (or the ones you want), then set the DisplayLabel property of each field. Hope that helps Share this post Link to post
MSiipola 0 Posted April 15, 2021 Here are some screen dumps on what happens. The first images shows the Object inspector when I have selected first column in object DBGrid. The second image shows the grid with data in the development GUI. The third images shows application during runtime. As you can see the name/header of the first column is not the same during development and runtime. During runtime it shows the database field name ('FNAME'). During development ('Medlemsnr'). Share this post Link to post
Guest Posted April 16, 2021 Long since i used vanilla DBGrid, but... try assigning to the grid datasource's dataset before opening it. Just a guess... Share this post Link to post
aehimself 396 Posted April 16, 2021 I think that whenever you change the datasource / dataset on the DBGrid it reinitializes everything, including the column captions you set in design time. To change the column caption, you can change the field's DisplayLabel property: dataset.FieldByName('FNAME').DisplayLabel := 'Medlemsnr'; This will cause the DBGrid to display that as a caption automatically when it creates the column. You'll still have to manually change the caption to bold every time, that is. 1 Share this post Link to post
MSiipola 0 Posted April 16, 2021 Thanks aehimself! Your suggestion solved the problem. Share this post Link to post