In the attached project I have a xamdatagrid with two combo box type controls on each row. When the value of one of the controls changes, I want to update the value of the other. For example, when the user uses the "Account number" control to select an account by account number, I want to update the "Account Name" control to refelect the selected account name. Please see the code below in MainWindow.xaml.cs:
private void SelectorTextBox_SelectionChanged(KeyValuePair<string, string> SelectedItem) { Trade t = (Trade)grid.ActiveDataItem; // Fails here because ActiveDataItem is null if row has not been committed. t.ACCT_NO = Convert.ToInt32(SelectedItem.Key); t.ACCT_Name = SelectedItem.Value; }
The problem only occurs if the user changes a control on the Add row, in which case the Active Data Item is null.
Thanks,
Sam
Hello Sam,
Thank you for your post. I have been looking into it and I can suggest using the ActiveRecord of the XamDataGrid, instead of the ActiveDataItem. You can use the DataItem property of the DataRecord (the active record) in order to get the Trade object and then you can implement the logic that you need. Here is how you can use the ActiveRecord property of the XamDatatGrid.
private void SelectorTextBox_SelectionChanged(KeyValuePair<string, string> SelectedItem)
{
if (grid.ActiveRecord != null)
DataRecord record = grid.ActiveRecord as DataRecord;
Trade t = (Trade)record.DataItem;
t.ACCT_NO = Convert.ToInt32(SelectedItem.Key);
t.ACCT_Name = SelectedItem.Value;
}
I have modified the sample application that you have provided me with, in order to show this approach and change the SelectorTextBox control with a ComboBox, since the assembly that contains the control was not included into your attachment.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Krasimir, thank you for your reply. Unfortunately the method still fails when the user changes the combobox on the "Add" row.
I need to find a way to remove this line: if (grid.ActiveRecord != null)
This method needs to work whenever the user has access to the combobox even if it is the add row of the grid.
Thank you, Sam