Hey Guys,
I have a XamDataGrid (Infragistics 14, .Net 4.0, Windows 7) with a couple of editable columns. Although these columns are generally editable, there are data points in each row that might make the particular cell read only. I am currently using the grid's EditModeStarting event to stop the ability to edit the cells that meet the particular condition.
This is working fine in regards to limiting the editability of the specific cell but I also need to remove the styling that I have on editable cells. All of my editable columns have a green background but the cells in these columns that meet the specific criteria should not have the green background. Is there a way to remove the styling so it never shows up on the cells that meet the read only criteria? Ideally, there would be an AllowEdit property that I can set on the cell level instead of just the field level - is there something like this?
Thanks in advance!
So I was able to fix both of my requirements by using the EditModeStarting event to cancel editing on cells that meet a criteria and the InitializeCellValuePresenter to remove the styling from cells that meet the criteria. Although this works fine, I'm wondering if there's a better way to go about doing this? Thank you.
In addition to the above two criteria, I need to remove any editorStyles associated with the specific cells that match the criteria - XamComboEditor or XamDateTimeEditor for example - because they end up showing dropdown keys even though the specific cell is not editable.
So in summary:
Any thoughts on my questions?
Hello Amilcar,
Thank you for your post(s).
I have been looking into this, and I believe a better way to do this would be to do this almost entirely in a Style for the CellValuePresenter. Using MultiDataTriggers, you can target the Field and the data item that the cell's ability to be edited is dependent on. If you set the IsEnabled property on the CellValuePresenter to False, I believe this will disable the ability to edit the cell. Then, using another trigger that is directed at the IsEnabled property, you can set the background of any CellValuePresenter that has IsEnabled = false to another color other than your default green background.
Regarding the removal of the editor style for cells that aren't editable, I would recommend writing a Style for that particular type of editor, and by using a DataTrigger with a RelativeSource AncestorType binding to the CellValuePresenter, you can apply an empty template to the editor in the cell if the IsEnabled property of the CellValuePresenter is set to False.
I am currently working on a sample to demonstrate the above. I will attach it in my next response to this forum thread which should be very soon.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hey Andrew,
Thank you for your reply! I'll give this a try and I look forward to your sample!
I'm having some trouble setting up my style for your sugested approach. I need to fullfill the following three cases:
The conditions are easy to represent in code but might be hard to do in a style because I need to access the values of other fields in the record and have "or" conditions.
Futhermore, I'm having issues binding to the cell value presenter's record property. My style is in the user control's resources section and I'm targeting the CellValuePresenter but when I bind the condition to the record property, xaml complains about not finding it. Any ideas? Thanks again!
Thank you so much for your assistance, your sample defintiely cleared up my questions and I got it working!
I have attached the sample project that was mentioned above.
Regarding the binding to the record of a CellValuePresenter, the record is the data context of the CellValuePresenter. Meaning if you do {Binding PropertyName} on a style for the CellValuePresenter, you are binding to a property on the DataRecord, and in this case, PropertyName would need to be a property on the record for this to work. If you would like to bind directly to the record itself, you can use a RelativeSource binding for {Binding RelativeSource={RelativeSource Self}, Path=DataContext} on the CellValuePresenter. I hope this helps you.