In this thread http://community.infragistics.com/forums/p/67703/343523.aspx#343523I asked how to rebuild a xamdatagrid - thank you for helping me make progress on that.As discussed in the thread above we are de-serializing values saved by the user and attempting to restore a XamDataGrid to a prior state.
So now I am able to get a reference to the XamComboEditor in my grid, however the ComboBox property is null and I do not understand why. Here is the XAML where the XamComboEditor is defined:
<Style x:Key="ParameterScopeStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider"> <Setter.Value> <igEditors:ComboBoxItemsProvider> <igEditors:ComboBoxItemsProvider.Items> <igEditors:ComboBoxDataItem DisplayText="PIMCO" Value="Pimco"/> <igEditors:ComboBoxDataItem DisplayText="Account" Value="Account"/> <igEditors:ComboBoxDataItem DisplayText="PM" Value="PM"/> </igEditors:ComboBoxItemsProvider.Items> </igEditors:ComboBoxItemsProvider>
</Setter.Value> </Setter> <Setter Property="Value" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value}"></Setter> <EventSetter Event="SelectedItemChanged" Handler="ParameterScopeChanged"/></Style>
<igDP:Field Name="Parameter"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource ParameterScopeStyle}"/> </igDP:Field.Settings></igDP:Field>
I am handling the DataRecordPresenter Loaded event here:
private void CashParameterGrid_DataRecordPresenter_Loaded(object sender, RoutedEventArgs e){ DataRecordPresenter presenter = sender as DataRecordPresenter; if (! presenter.Record.IsDataRecord) return;
var cell = (presenter.Record as DataRecord).Cells[0]; CellValuePresenter cvp = CellValuePresenter.FromCell(cell); if (cvp == null) return;
XamComboEditor editor = cvp.Editor as XamComboEditor; ParameterScopeChanged(editor, e);}
In the code below I need to access the ComboBox property of the passed XamComboEditor however that property is always null:
private void ParameterScopeChanged(object sender, RoutedEventArgs e){ // scopeCombo is a list of data types XamComboEditor scopeCombo = ((XamComboEditor)sender); DataRecord record = (DataRecord)scopeCombo.DataContext; CellValuePresenter cvp = CellValuePresenter.FromCell(record.Cells[1]);
if (cvp == null || scopeCombo.ComboBox == null) return;
// valueCombo is a list of values of the type specified by scopeCombo XamComboEditor valueCombo = (XamComboEditor)Infragistics.Windows.Utilities.GetDescendantFromType(cvp, typeof(XamComboEditor), false); ComboBoxItemsProvider provider = null;
if(valueCombo.ItemsProvider == null) { provider = new ComboBoxItemsProvider(); valueCombo.ItemsProvider = provider; } else provider = valueCombo.ItemsProvider;
provider.DisplayMemberPath = ""; switch (scopeCombo.ComboBox.SelectedValue.ToString()) { case "PIMCO": valueCombo.ItemsProvider = null; break;
case "Account": provider.ItemsSource = ViewModel.Accounts; break;
case "Strategy": provider.ItemsSource = ViewModel.Strategies; break; case "PM": provider.ItemsSource = ViewModel.PM_Names; provider.DisplayMemberPath = "Name"; provider.ValuePath = "Name"; break;
default: throw new Exception("Scope not recognised: " + scopeCombo.ComboBox.SelectedValue.ToString()); }
if (valueCombo.ItemsProvider != null && valueCombo.ItemsProvider.Items.Count > 0) valueCombo.SelectedIndex = 0;}
Hello Sam,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
.StartEditMode() was what I needed. Thanks for pointing me in the right direction!!
Thank you for your post. I have been looking into it and I can say that this behavior is expected, since the ComboBox Property is set when you the XamComboEditor is in edit mode and because of a virtualization, when you exit edit mode, the reference is released.
Hope this helps you.