Load all Data from DB to FNC DataGrid and then hide many columns

I want to load a Database-Table into my FNCDataGrid and then only show a view Columns in the Grid.
Then close the Database and only work offline.
The Datagrid is then only ReadOnly for the Grid.
After click at one column, all Data from this Column should be read into the editfields of my Form, not only the listed ones.
The Table has 40 Fields and i want to show only 10 of it.

My idea would be:
I can set a Const Array for this Form and Table and set the the Fields i would show as 1 ore true and the hidden one as 0 or False.

I want to use the Grid like a memory Table, so i can do any filtering and sorting and reading without using the network.
The Form with all the Fields in a record should show all Data from one Record after changing the row-selection in the Grid.
If i am ready with changing editfields in my Form, i will change the color of my SaveButton at the Form and the user could click this button to save the Record to the Database.

What is the easiest way to do this?

Hi,

You are basically free to do what you want with the grid, note that all data is accessible even though the columns are hidden. If you want to load all the data in the grid from a dataset you can set:

  TMSFNCDataGridDatabaseAdapter1.LoadMode := almAllRecords;
  TMSFNCDataGridDatabaseAdapter1.LoadAllData;
  TMSFNCDataGridDatabaseAdapter1.KeepData := True;
  ClientDataSet1.Active := False;

The data will persist in the grid.

If you want to load only 10 of the 40 columns in the grid, you would need to do this first:

  TMSFNCDataGridDatabaseAdapter1.AutoCreateColumns := False;
  TMSFNCDataGridDatabaseAdapter1.FieldNames[0] := 'Category';
  TMSFNCDataGridDatabaseAdapter1.FieldNames[1] := 'Notes';

Note that once you lose connection with the dataset or work "offline", you cannot synchronize the current active record and therefore the linked fields of other controls will not automatically update. You'll have to manually go through the data of the grid and transfer it to your form.

Thanks
Your first answer to load all Date to the Grid is what i want to do.
But after this i only want to SHOW 10 of 40 Columns in the Grid.
Do i have to hide all not to show Columns or is there another way to only show Field x7,x2,x5,x14...
How can i change the Position of the Columns other as in the Database.

I think your second answer is only useable if i do not need all data.
But i need all data in the grid but only want to show only 10 to the user.

If you load all columns ,then you can use HideColumn functionality. You can get the column index by the header ('fieldname'):

  TMSFNCDataGrid1.HideColumn(TMSFNCDataGrid1.ColumnIndexByHeader('MyFieldName'));

If you want to change position, you either manually add all columns in the order you wish via the second method, or you change the index via the following code after you disconnect:

TMSFNCDataGrid1.SwapColumns(TMSFNCDataGrid1.ColumnIndexByHeader('MyFieldName'), TMSFNCDataGrid1.ColumnIndexByHeader('MyOtherFieldName'));

This options are not accessible in my Project.
They are also not in the ObjectInspector:
grafik

oops
I found that i used the wrong Adapter.
TMSFNCGridAdapter instead of TMSFNCDataGridAdapter.

1 Like

I have load the Datagrid with
TMSFNCDataGridDatabaseAdapter1.LoadMode := almAllRecords;
TMSFNCDataGridDatabaseAdapter1.LoadAllData;
TMSFNCDataGridDatabaseAdapter1.KeepData := True;
TMSFNCDataGridDatabaseAdapter1.AutoCreateColumns := True;

The Grid show the Data and at the Boolean Column Passiv it show a Checkbox.
With and without Checked.

If i try to read this Column:
chkPassiv.Checked:=frmMain.DataGrid.Cells[frmMain.DataGrid.ColumnIndexByHeader('Passiv'),lRow].AsBoolean;
the Result is always False in all rows.
If i use .AsInteger the Resut is 0

Do i made somthing wrong?

For checkboxes, you actually want to use

chkPassiv.Checked := frmMain.DataGrid.Booleans[frmMain.DataGrid.ColumnIndexByHeader('Passiv'),lRow];

This works.

I cant find a Event for RowChange so i can fill my Form-components withe the Data out of the Grid when the user change the Row with Cursor or Click.

What Event should i use.

Use the OnSelectCell event.