Jump to content
MSiipola

Problem with TBGrid connected to SQLite

Recommended Posts

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

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

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').

 

afkdb1.jpg

afkdb2.jpg

afkdb3.jpg

Share this post


Link to post
Guest

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

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.

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×