I am using the xamDataGrid in an XBAP and I need to know how to change a single row's style and AllowEdit property based on whether the value in one of the columns is null or not.
So: If Column A is not null, the row should be read-only and have style 1, but if Column A is null, the row should be editable and have style 2.
Column A is collapsed and non-editable, so there is no need to worry about its value changing during operation. The xamDataGrid is bound to a DataTable, and I am working in C#.
You could bind the AllowEdit property to the data and add a custom IValueConverter which returns true or false based on the value of the data.
If you'd like me to write some code to demonstrate, I'd be happy to.
Some sample code would be very useful. Thanks.
Hello,
After consulting with engineering, it looks like the idea of using Binding will not work in this scenario. However, I have this working by handling the OnEditModeStarting event.
Assign an event handler to the OnEditModeStarting for the ValueEditor you wish to apply the read only logic to:
<igDP:Field x:Uid="Title" Name="Title"> <igDP:Field.Settings> <igDP:FieldSettings CellMinWidth="250" CellWidth="250"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:ValueEditor}" > <EventSetter Event="EditModeStarting" Handler="OnEditModeStarting"/> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings></igDP:Field>
Then, in the code-behind cancel editing when you want the field to be read-only:
void OnEditModeStarting(object sender, Infragistics.Windows.Editors.Events.EditModeStartingEventArgs e){ if (sender is XamTextEditor && !string.IsNullOrEmpty(((XamTextEditor)sender).DisplayText)) { e.Cancel = true; }}
Let me know if thei helps.
Thanks!
Hello Valeria,
Can you put together a small sample which illustrates the problem? With a sample, I can help come up with a solution faster.
Thanks,
Any thoughts on this in the past month and a half? I'm still thoroughly stumped.
Hi, and thanks for your response. That helps with keeping the rows' values as read-only (I could check if the column with the deciding variable was null or not), but doesn't help with changing the row style (or CellValuePresenterStyle for each cell in the row) based on that same value. In my application I have a seperate look for controls that can receive input. This means that if the read-only cells use the default style for their fields, it will be very confusing for the user.