Hi there,
i have one dataset with two datatables. one datatable is related to the other table like this:
DataSet Test = new DataSet();
DataTable Parrent = new DataTable();
Parrent.Columns.Add(New DataColumn("Customer"));
Test.Tables.Add(Parrent);
DataTable Child = new DataTable();
Child.Columns.Add(New DataColumn("Customer"));
Test.Tables.Add(Child);
in my xamdatagrid they were shown correctly with the Plus to expand.
But now i want to hide the Customer-Column in the Child-Table and all the ColumnHeaders in the Child-Table.
Is this possible somehow?
regards
Cloud
Hello Cloud,
You can replace the code I gave you with the following one:
private void xamDataGrid1_EditModeEnded(object sender, EditModeEndedEventArgs e) { foreach (var field in e.Cell.Record.ChildRecords[0].ChildRecords[0].FieldLayout.Fields) { if (field.Name == e.Cell.Field.Name) { foreach (var record in e.Cell.Record.ChildRecords[0].ChildRecords) { CellValuePresenter.FromRecordAndField((record as Record) as DataRecord, record.FieldLayout.Fields[e.Cell.Field.Name]).Value = "NewValue"; } } } }
Hope this helps you.
that´s a nice try and it work partly.
but with some cells in the grid the CellValuePresenter.FromRecordAndField((item as Record) as DataRecord, item.FieldLayout.Fields[e.Cell.Field.Name] is null and it brings me a nullreference exception. can you imagine why this happens? it´s just on some cells but this cells shouldn´t differ from the others...
regards cloud
I can suggest you handle the XamDataGrid’s EditModeEnded event and add the following handler:
private void xamDataGrid1_EditModeEnded(object sender, EditModeEndedEventArgs e) { foreach (var item in e.Cell.Record.ChildRecords[0].ChildRecords) { CellValuePresenter.FromRecordAndField((item as Record) as DataRecord, item.FieldLayout.Fields[e.Cell.Field.Name]).Value = "NewValue"; } }
thank you for your answers.
now i´m very desperating because i do not get out how i can get the cells from a field.
because i want something like this: if i edit one value in the parent-row, the complete column (with the same header) in the child row should get the same value.
but i can´t figure out how i can set the value in the cells of one specific field.
could you help me out pls?
best regards
cloud
You can set the Visibility Property of the Field to Collapsed instead of Hidden.