I have a grid where I'd like to keep using Autogenerated=true when binding to my datasource.
I've set the Fieldsettings to AllowEdit=false to prevent inline fields being edited, but I would like to enable some checkboxes given its data.record meets a particular condition.
For example: Enable checkboxes only when Id > 100 (dashes are disabled checkboxes, brackets are enabled checkboxes)
chkbox Id Date otherstuff...
- 20 1/10/2015 test
- 99 1/5/2015 stuff
[v] 101 1/4/2015 notes
Is this possible? And can I bind a command to the checkbox event to capture this change while conforming to MVVM pattern?
Hello Patrick,Thank you for the provided explanation.I have been looking into your issue in regards to adding checkboxes which are enabled only if a particular cell of the current DataRecord meets certain condition. You should be able to achieve this along with the MVVM pattern by creating an EditorStyle for the Checkbox field and add a couple of Setters for the IsChecked and the IsEnabled properties of the editor respectively.1) The IsChecked property will be bound to a custom property of our DataItem (for example IsItemChecked).
<Setter Property="IsChecked" Value="{Binding DataItem.IsItemChecked, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />2) The IsEnabled property will be bound to a custom property of our DataItem (for example IsItemEnabled).
<Setter Property="IsEnabled" Value="{Binding DataItem.IsItemEnabled, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />The bindings are two-way which means that your DataItem's properties will be set accordingly.3) The Enabled/Disabled logic for the XamCheckEditors can be implemented inside the setter of the field whose value we consider the condition (for example Price). This way every time the Price has been set, we set the IsItemEnabled to either true or false, depending on condition for the price.public double vmPrice{ get { return this.Price; } set { if (value < 1000) this.IsItemEnabled = false; else this.IsItemEnabled = true;
if (value < 0.0) this.Price = 0.0; else this.Price = value; NotifyPropertyChanged("vmPrice"); }}Since we have bound the IsItemEnabled property to the IsEnabled property of the XamCheckEditor for the current record, the XamCheckEditor will be checked/unchecked accordingly as well. I have prepared a sample application where this behavior has been implemented.Would you please take a look at the sample and if you are still experiencing any issues or this is not the behavior you were aiming for, please let me know.
Thank you for your response. I am running 14.1 which does not have the property "AllowEdit=True" in the line
<igDP:Field Name="IsItemChecked" AllowEdit="True" >
Is this still possible with 14.1?
Hello Patrick,The answer to your question is yes, this property can be set in 14.1. Since the AllowEdit property has been introduced as a property of the Field class in 14.2 product version, you can set it in 14.1 by accessing the FieldSettings of the corresponding Field:<igDP:Field Name="IsItemChecked" > <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="True" /> </igDP:Field.Settings></igDP:Field>If you require any further assistance on this matter, please do not hesitate to ask.
Thank you, this works great but I'm noticing some strange events.
The field bound to the checkbox IsChecked attribute is called as I scroll in my grid. I notice this does not happen with the example you provided so I am not sure what is causing these setter to be called during scrolling events.
My XamDataGrid is within a usercontrol, within a XamTabControl.
Any ideas?
Hello Patrick,
I am glad to know you were able to solve your issue. I believe this thread can help other people looking for a similar solution.
If you require any further assistance on the matter, please let me know.
I changed the default RecordContainerGenerationMode to "LazyLoad" and this seem to fix the issue. Thanks for your help
I have been looking into the behavior you have described when using the XamDataGrid inside a XamTabControl within a UserControl and I was not able to reproduce it.
Would you please take a look at the sample I have attached and modify it accordingly so the issue is reproduced? It would be great if you could provide me with detailed steps for reproducing the issue as well. Having this information would help me further investigate this matter for you.
Looking forward to your reply.