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
130
DataContext in AddNew row
posted

I'm trying to disable a column based on another column. Seems easy and works fine when the record is not a newly added record. I have 2 fields. For simplicity lets make the first a boolean - IsEnabled and the second a string - Result. Result should only be enabled when IsEnabled is True. Here's my Result column:

<igDP:Field Name="Result">

      <igDP:Field.Settings>

            <igDP:FieldSettings >

                  <igDP:FieldSettings.EditorStyle>

                        <Style TargetType="{x:Type igEditors:XamTextEditor}">

                              <Setter Property="IsEnabled" Value="{Binding Path=DataItem.IsEnabled}"/>

                        </Style>

                  </igDP:FieldSettings.EditorStyle>

            </igDP:FieldSettings>

      </igDP:Field.Settings>

</igDP:Field>

 The question is why doesn't this work in the Add New row (or any records added from the AddNew row). Is there something else I can access other than DataItem? We've seen the problem before for CellValuePresenters - to resolve that we added the following code to the RecordAdded event, but I'm not sure how to grab the Editor and I'd rather get to the root of the problem instead of working around it:

 void XamDataGrid1_RecordAdded(object sender, Infragistics.Windows.DataPresenter.Events.RecordAddedEventArgs e) {
    Cell periodCell;
    Style cellStyle;
    CellValuePresenter cellPresenter;
    periodCell = e.Record.Cells["Result"];
    if (periodCell != null) {
      if (periodCell.Field.HasSettings) {
        cellStyle = periodCell.Field.Settings.CellValuePresenterStyle;
        if (cellStyle != null) {
          cellPresenter = CellValuePresenter.FromRecordAndField(periodCell.Record, periodCell.Field);
          cellPresenter.DataContext = null;
          cellPresenter.DataContext = e.Record;
        }
      }
    }
}

Parents
No Data
Reply
  • 85
    posted

    This smells a lot like a problem I'm having when I add new Records using the AddRow.  My Data bindings to a DataSet/DataTable just don't seem to kick in.  The cells I type'd into during the AddRow operation have the new values, but if I subsequently update the values in the DataRow object, the XamDataGrid does not seem to update.   Unlike what you are seeing, I am not using a special cell presenter -- just the defaults.

     

     

Children
No Data