Add Empty Column when SfDataGrid is bound to DataTable

Hi

This is a graphical issue.

I don't know how to add an empty column to SfDataGrid when ItemSource is bound to a DataTable, because i dont know how many columns will be loaded.

This is the result i would like to achieve using ColumnSizer="AutoWithLastColumnFill".

 In this case i set the columns in XAML.



But when i bound ItemSource to a DataTable, columns are auto-generated because i dont know at design time the table resulting from a user generated query.

The default behaviour of SfDatagrid is this one



So

How can i add an empty column when SfDataGrid is bound to DataTable

Th


1 Reply

SJ Sathiyathanam Jeyakumar Syncfusion Team January 19, 2023 05:20 PM UTC

Hi Michele,

Your requirement can be achieved by adding the dummy columns in a loaded event of datagrid. Refer to the below code snippets.

Here's an example of how you can achieve this:

 

this.DataGrid2.Loaded += DataGrid2_Loaded;

 

private void DataGrid2_Loaded(object sender, RoutedEventArgs e)

{

    this.DataGrid2.Columns.Add(new GridTextColumn()

    {

        MappingName = "Dummy" ,

        HeaderText = "",

        AllowFiltering = false,

        AllowGrouping = false,

        AllowSorting = false,

        AllowEditing = false,

    });

}


Regards

Sathiyathanam


Attachment: DataTableDemo_611504ba.zip

Loader.
Up arrow icon