Hi I would to ask help regarding binding data to the data grid. On the program we are creating, we have this dynamic grid columns which requires manually setting the columns.
Just to give you an info, the data to bind does not have any "Class" to be used as an ObservableCollection, instead, we are manually creating the DataTable that contains the generated data.
The columns for this is also dynamic which comes from a source information from the server. So basically, the data grid will contain different view of columns depending on the data populated.
How can you help me to make this thing works. We are using SfDataGrid as this is the only component which we can really use on our project.
A simple example below which I hope can give you idea how can you possibly help me.
Page.xaml.cs
private void BuildGrid()
{
{
dataGrid.Columns.Clear();
foreach (GridColumnDefinition colDef in App.CurrentApp.DynamicGridColumns)
{
GridTextColumn textColumn = new GridTextColumn();
textColumn.HeaderText = colDef.HeaderText;
textColumn.MappingName = colDef.Name;
textColumn.LineBreakMode = LineBreakMode.WordWrap;
textColumn.TextAlignment = TextAlignment.Center;
dataGrid.Columns.Add(textColumn);
}
}
}
PageViewModel.cs
var bindTask = GenerateDataTable(dynamicSRC); *
GridData = await bindTask; **
* dynamicSRC - is the dynamic source contains
** GridData - is the DataTable
Page.xaml
<syncfusion:SfDataGrid x:Name="dataGrid" ItemsSource="{Binding GridData}" SelectionMode="Single" ColumnSizer="Star" AutoGenerateColumns="False" RowHeight="55" HeaderRowHeight="50" ScrollingMode="PixelLine"
Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" VerticalOptions="FillAndExpand">
</syncfusion:SfDataGrid>
After we have successfully populated the DataTable, it seems that there is nothing happen to the datagrid. No Columns, No Rows, nothing at all. We will be glad at most if you can help us regarding this problem. We just really can't figure out how to successfully work this.
Thank you.