josephkim
2022-11-29T18:15:58Z
Hello,

In my MainForm, I have added multiple columns to the Grid as follows:

string[] columnNames = { "Name", "Age", "Gender", "Country" };
columnNames.ForEach(columnName =>
            {
                 iGridView1.Cols.Add(columnName);
            });

and in another class, I have a DataTable,

var table = new DataTable();
table.Columns.Add("Name");
table.Columns.Add("Age");
table.Columns.Add("Gender");
table.Columns.Add("Country");

However, when I attempt to call
iGridView1.FillWithData(table, true);
to keep the current col set, the Grid doesn't populate, but when it's false, it works.

When it's set to false, the grid gets populated with the same amount of rows, but the data are blank.

The addition of the columns on datatable is just for formality.

How do I achieve that?
Igor/10Tec
2022-11-30T16:20:22Z
The easiest way to show a DataTable in iGrid is to call its FillWithData method with one parameter in which you pass the DataTable. In this case iGrid will show all columns from the DataTable.

If you want to show a subset of the columns, you may go the way you showed. The only missing element in your implementation is column keys. iGrid uses them to bind iGrid columns to corresponding DataTable columns. In the general case column titles may differ from column keys, so that you need to specify both with the following overloaded version of the Cols.Add() method:

string[] columnNames = { "Name", "Age", "Gender", "Country" };
columnNames.ForEach(columnName =>
            {
                 iGridView1.Cols.Add(columnName, columnName);
            });

The first parameter of Cols.Add(String, String) is the column key, the second is the column title.