I have a xamcombobox with selected value bound to a property on my entity class.
When the user adds a new row to the grid I need to set the value of the bound property to a default value. I want the combox to reflect that value.
However, the dataitem for TemplateAddRecord is null until the user makes some change. Since my combobox is bound to the dataitem (which is null) it does not display any value at all.
What is the best way to accomplish this?
Thanks,
Sam
Example:
In XAML <XamComboEditor Value = "{Binding DataItem.StateCode}"/>
In Grid_InitialzeTemplateAddRecord:
e.TemplateAddRecord.Cells["StateCode"] = "CA"; // Set default to California. Combobox should update to reflect this but it does not (because dataitem is null???)
I created a small project to illustrate the issue discussed in the first post, plus a related issue.
Issue 1 (discussed in the first post in this thread):When starting the attached example note that the gender dropdown does not display a value even though the cell value is set.Put the cursor in the name column and type something. The Gender_SelectedItemChanged fires even though the underlying value has not changed from the time the record was initialized. I dont beleive the SelectedItemChanged event should fire because the combobox should be binding to the value AFTER it is set in the InitializeTemplateAddRecord method.
Issue 2:Highlight any of the previously saved rows and press delete. For some reason Gender_SelectedItemChanged fires again (and throws an error).
Have you guys had a chance to look at this?
Thanks very much,
Hello Sam,
Thank you for your post. I have been looking into it and the sample you have provided and I suggest you bind your XamComboEditor’s Value Property like this:
<Setter Property="Value" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value}"></Setter>
Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.