I am pretty new to Xaml. I want to hide one column "Id" from my XamDataGrid
which is bound to a datatable in viewmodel. I tried the below approach:
private void xamDataGrid1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)
{
xamDataGrid1.FieldLayouts[0].Fields["ID"].Visibility = Visibility.Collapsed;
}
But when I run the code first time, I get the below Exception:
System.ArgumentException: 'key not found'
Is there any way to check if the Field["Id"] exists or not before running the above code?
The below one worked for me:
private void XamDataGrid_RecordsInViewChanged(object sender, Infragistics.Windows.DataPresenter.Events.RecordsInViewChangedEventArgs e)
{
int count = 0;
count = XamDataGrid.DefaultFieldLayout.Fields.Count(field => field.Name.CIeq("Id"));
if (count > 0)
XamDataGrid.DefaultFieldLayout.Fields["Id"].Visibility = Visibility.Collapsed;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.