Hello. I would simply like to disable a column in the XamDataGrid. I know I can do this:
((XamDataGrid)sender).FieldLayouts[0].Fields["Total"].Settings.AllowEdit = false;
but I want the column to took like if I was going to do something like this:
((XamDataGrid)sender).Records[2].IsEnabled = false;
So grayed out.
How can I do this?
Thanks
Hello Kris,
I believe that setting the IsEnable property of the CellValuePresenters that are displayed in the same field, will help you achieve the functionality you need. Below is a code snippet that grey out the cells in a specific field and does not allow editing:foreach (DataRecord record in ((XamDataGrid)sender).Records) { if (record != null) { CellValuePresenter.FromCell(record.Cells["name"]).IsEnabled = false; } }I hope it will be helpful for you.
Hi Maria,
The column that I'm working with is called "Total". I'm getting a NullPointerException in this statement CellValuePresenter.FromCell(record.Cells["Total"]). When debugging I can see that there is an initialized object in record.Cells["Total"].
Thank you for the update Kris. I am glad that this approach helped you.
It did work. Thanks.
I am just checking your progress on the issue.
If you require any further assistance, please do not hesitate to ask.
Kris,
You can try to use a Dispatcher to change the priority of the operations and make sure that the CellValuePresenter was created. I am attaching here a sample application I have used to test this behavior that could be illustrates the approach.