Dear,
I have used SQL datatable as Itemsource in datagrid. My data grid works fine as per column structure defined in data table. after data binding, I want to change column type combo box from character type.
I am using following code.
dataGrid.AutoGenerateColumns = true;
viewModel.DataTable = JsonConvert.DeserializeObject<DataTable>(jsonResp["data"].ToString().Trim());
List<PCls_SQLTblFldDef> TblStru = JsonConvert.DeserializeObject<List<PCls_SQLTblFldDef>>(jsonResp["adtData"].ToString().Trim());
dataGrid.ItemsSource = viewModel.DataTable;
dataGrid.AutoGeneratingColumn += (sender, e) => Global.GridColumnManipulate(sender, e, TblStru, dataGrid);
GridColumnManipulate will be called from
dataGrid.AutoGeneratingColumn event
public static void GridColumnManipulate(object sender, AutoGeneratingColumnEventArgs e, List<PCls_SQLTblFldDef> TblStru, SfDataGrid dataGrid)
{
int nTblStruLen = TblStru.Count;
e.Column.HeaderFontAttribute = FontAttributes.Bold;
for (int iCtr = 0; iCtr < nTblStruLen; iCtr++)
{
if (TblStru[iCtr].FldName == e.Column.MappingName)
{
string MapName;
MapName = e.Column.MappingName;
if (TblStru[iCtr].Hidden == "Y" || MapName.ToUpper() == "MSTID" || MapName.ToUpper() == "SR")
{
e.Column.IsHidden = true;
}
if (MapName.ToUpper() == "SRL")
{
e.Column.AllowEditing = false;
}
else if (MapName.ToUpper() == "FLDTYPE") {
e.Cancel = true;
List<string> DataTypes = new List<string>
{ "C", "N", "D", "B" };
e.Column = new GridComboBoxColumn() {
ItemsSource = DataTypes,
MappingName="FldType",
HeaderText = "FldType",
AllowEditing = true
};
//dataGrid.Columns.Add(e.Column);
//int index = dataGrid.Columns.IndexOf(e.Column);
dataGrid.Columns.Insert(2, ComboCol);
}
if (TblStru[iCtr].DataType == "Int32")
{
e.Column.TextAlignment = TextAlignment.End;
e.Column.Padding = 5;
}
else if (TblStru[iCtr].DataType == "String")
{
e.Column.TextAlignment = TextAlignment.Start;
e.Column.Padding = 5;
}
//dataGrid.Columns.Resume();
//dataGrid.RefreshColumns();
}
}
}
Now my problems:
Please support me for above problems. what's the wrong with my code.
Thanking you.
Hi Amish,
Currently, we are validating the reported scenario on our end. We will update you with further details on or before August 17, 2022. We appreciate your patience until then.
Regards,
Suja
Hi Amish,
We would like to let you know that using AutoGenerateColumn event we can customize the columns being generated automatically. You can achieve your requirements in GridLoaded event by removing required column and create new combobox column based on your requirement. Please refer our user guidelines documentation regarding GridLoaded event in the below link.
UG link: https://help.syncfusion.com/xamarin/datagrid/grid-events#gridloaded-event
Please let us know if you need any further assistance.
Regards,
Suja
My problem solved as you suggested.
Thank you.
Hi Amish,
Thank you for the update. We are glad that our solution meets your requirements. Please let us know if you need further assistance. As always, we are happy to help you out.
Regards,
Suja