Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
150
XamDataGrid - Issue finding if the cell is read only or not
posted

I have XamDataGrid with PreviewKeyDown subscribed. I am iterating selected Cells here and want to find out if a Cell is read only or not.

Tried Approaches:

1. Cell.Field.AllowEdit - This value is always null and AllowEditResolved always True

2. Cell -> CellValuePresenter.Editor.IsReadOnly - This approach works but only for Cells visible on screen (Virtualization). In real use-case here, selected Cells could be out of visible area on screen. 

Any suggestion to get around this issue please? 

Thanks, Nikhil

Parents
No Data
Reply
  • 34430
    Offline posted

    Hello Nikhil,

    Regarding the Cell.Field.AllowEdit property, this property being null is expected if you do not set it explicitly, and if this property is not set, the AllowEditResolved property returning true is also expected, as you will be able to consistently enter edit mode on the cell.

    Being that the CellValuePresenter.Editor.IsReadOnly property is working for you on this matter for the cells that are in view, I have to assume that you are setting that property, perhaps in an EditorStyle. I am also under the impression that this IsReadOnly property is likely based on a condition and is not set across the entirety of the XamDataGrid.

    If my impression above is correct, and the IsReadOnly property of your editor is being based on some condition, I would recommend that you check this condition for each cell in the XamDataGrid.SelectedItems.Cells collection. Each cell in this collection will have a reference to the DataRecord element that owns it via the cell's Record property, and the DataRecord will have a DataItem property that returns the data item that represents that particular record. If, perhaps, this IsReadOnly property setting on your editors is based on some condition(s) in your data item, I would recommend that you check your data item against these conditions to see if the cell is read only or not.

    If my impression above is incorrect, and the IsReadOnly property is set to the same value across the entirety of your Field's editors, then I would recommend getting the records that are in view by using the XamDataGrid's GetRecordsInView method and selecting an arbitrary cell from that collection that exists for your Field. This will allow you to get the CellValuePresenter, as the record will be in view, and check the Editor.IsReadOnly property on it. You can get the CellValuePresenter by using the static CellValuePresenter.FromCell(Cell c) method.

    I hope this helps. Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

Children
No Data