BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Sir/Madam,
I am using SFDataGrid in Xamarin. I have attached my sample code herewith. I get error on line
dataGrid?.GroupColumnDescriptions?.Clear(); in OnAppearing method
Actually, I am generating report with some column grouping with default column, columnn grouping is successfully done. Once report is generated with default column grouping, I have given provision to change column grouping on runtime. When I change column grouping on runtime then I get error.
public RptViewer()
{
InitializeComponent();
dataGrid.GridStyle.AlternatingRowColor = Color.LightGray;
CoreFunction.ResetParentModDet();
Title = ParentModDet.ModName;
//dataGrid.GridLoaded += DataGrid_GridLoaded;
GenerateReport();
}
protected override void OnAppearing()
{
base.OnAppearing();
ParentModDet.Collection = Global.ParentMod_Collection;
NewGrpByFld = ParentModDet.Collection;
try
{
if (dataGrid == null || dataGrid.GroupColumnDescriptions == null)
return;
dataGrid.GroupSummaryRows.Clear();
dataGrid?.GroupColumnDescriptions?.Clear();
dataGrid.GroupColumnDescriptions = new GroupColumnDescriptions();
if (NewGrpByFld != null)
{
for (int iCtr = 0; iCtr < NewGrpByFld.Count; iCtr++)
{
dataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
{
ColumnName = NewGrpByFld[iCtr].ToString(),
SortGroupRecords = true
});
}
}
else
{
for (int iCtr = 0; iCtr < DefGrpByFld.Count; iCtr++)
{
dataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
{
ColumnName = DefGrpByFld[iCtr].ToString(),
SortGroupRecords = true
});
}
}
GridGroupSummaryRow gridGroupSummaryRow = new GridGroupSummaryRow
{
ShowSummaryInRow = false,
SummaryColumns = new ObservableCollection<ISummaryColumn>()
};
foreach (RptViewFldDef FldName in RptFld)
{
if (FldName.Total)
{
GridSummaryColumn gridSummaryColumn = new GridSummaryColumn
{
MappingName = FldName.FldName,
Name = FldName.FldName,
SummaryType = SummaryType.DoubleAggregate,
Format = "{Sum}"
};
gridGroupSummaryRow.SummaryColumns.Add(gridSummaryColumn);
}
}
dataGrid.GroupSummaryRows.Add(gridGroupSummaryRow);
}
catch (Exception ex)
{
DisplayAlert(Global.strMsg, ex.Message, "OK");
}
}
async void GenerateReport()
{
Loader.IsRunning = true;
Loader.IsVisible = true;
MessagingCenter.Unsubscribe<List<RptViewFldDef>>(this, "SendCriToRptViewer");
MessagingCenter.Subscribe<List<RptViewFldDef>>(this, "SendCriToRptViewer", (RetVal) =>
{
MessagingCenter.Unsubscribe<List<RptViewFldDef>>(this, "SendCriToRptViewer");
RptFld = RetVal;
});
ClsGetTableData oTblData = new ClsGetTableData
{
ModName = ParentModDet.ModName,
QueryType = "D",
WhereCond = ParentModDet.StrParam
};
string json = JsonConvert.SerializeObject(oTblData);
HttpResponseMessage response = await CoreFunction.CallPostAPIAsync("GetDynaModData", json);
if (response.IsSuccessStatusCode)
{
string strAPIResp = await response.Content.ReadAsStringAsync();
JObject jsonResp = JObject.Parse(strAPIResp);
if (jsonResp["status"].ToString() == "Error")
{
await DisplayAlert(Global.strMsg, jsonResp["msg"].ToString(), "OK");
}
else
{
dataGrid.AutoGenerateColumns = true;
DataTable dt = new DataTable();
dt = JsonConvert.DeserializeObject<DataTable>(jsonResp["data"].ToString().Trim());
dataGrid.CanUseViewFilter = true;
FilterDV = new DataView(dt);
dataGrid.ItemsSource = FilterDV;
List<PCls_SQLTblFldDef> TblStru = JsonConvert.DeserializeObject<List<PCls_SQLTblFldDef>>(jsonResp["adtData"].ToString().Trim());
dataGrid.AutoGeneratingColumn += (sender, e) => CoreFunction.GridColumnManipulate(sender, e, TblStru);
dataGrid.LiveDataUpdateMode = LiveDataUpdateMode.AllowDataShaping;
//dataGrid.GridLoaded += (sender, e) => DataGrid_GridLoaded(sender, e, dataGrid);
//dataGrid.ValueChanged += (sender, e) => DataGrid_ValueChanged(sender, e, dataGrid);
//dataGrid.SelectionController = new ListGridController(dataGrid);
FilterCond = CoreFunction.RetFilterCond(TblStru);
GridTableSummaryRow summaryRow = new GridTableSummaryRow
{
ShowSummaryInRow = false,
Title = "Total",
Position = Position.Bottom
};
//dataGrid.GroupColumnDescriptions.Clear();
dataGrid.TableSummaryRows.Clear();
foreach (RptViewFldDef FldName in RptFld)
{
if (FldName.Total)
{
summaryRow.SummaryColumns.Add(new GridSummaryColumn()
{
Name = FldName.FldName,
MappingName = FldName.FldName,
Format = "{Sum}",
SummaryType = SummaryType.DoubleAggregate
});
}
else if (FldName.GrpBy)
{
DefGrpByFld.Add(FldName.FldName);
}
}
dataGrid.TableSummaryRows.Add(summaryRow);
}
}
else
{
await DisplayAlert(Global.strMsg, response.StatusCode.ToString(), "Ok");
}
Loader.IsRunning = false;
Loader.IsVisible = false;
}
I have enclosed error image and stacktrace in attached zip file.
Please do the needful.
Thnaking you.
Hi Amish,
We have checked the reported query “Error in xamarin sfdatagrid dataGrid?.GroupColumnDescriptions?.Clear() statement”, we have created a sample with DataTable, GroupColumnDescriptions, we are unable to reproduce the reported crash at our end, we have attached the sample with recent SfDatagrid and Xamarin. Forms NuGet version, please have a look at it and let us know if we have missed any customization that you have done in your sample.
If possible, could you please modify the sample to replicate the issue or replication the procedure or video to reproduce the issue at our end. Which will be more helpful for us to find the solution as soon as possible.
Regards,
Suthi Yuvaraj.