Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3160
How to get DataItem for AddRecord?
posted

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

 

 

XamGridEditorTest.zip
Parents
  • 30945
    Offline posted

    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

    XamGridEditorTest_1.zip
Reply Children