OK, this has been driving me crazy all morning. I have a XAMDataGrid and I am trying to put a combo box inside one of the cells. It shows up ok, but the combo box remains empty no matter what I try. I had this working in regular datagrid, but switching to the XAMDataGrid I cannot make it work. Here's the code
<igDP:XamDataGrid AutoFit="True" DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="Checked" Label="Output"/> <igDP:Field Name="ColumnAlias" Label="Column"/> <igDP:Field Name="selectedOperator" Label="Operator"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding Operator}"/> <Setter Property="SelectedItem" Value="{Binding selectedOperator}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Criteria" Label="Criteria"/> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Operator is an observablecollection<string> property defined as..
private ObservableCollection<string> _operator = new ObservableCollection<string>() {"=","<>",">",">=","<","<=","IN","IS NULL","IS NOT NULL"}; public ObservableCollection<string> Operator { get { return _operator; } }
Everything else binds correctly, but the combo box shows empty. Any ideas?
Hi Sam,
Thanks for the reply, the datacontext for the combo box is the same as the datacontext of the datagrid (I am not explicitly setting the datacontext of the grid, but it is the lone item within a user control and the user control is set with the datacontext I'm interested in). The normal fields are pulling the correct values, but when I try to bind itemssource to a array of strings it is not displaying correctly. Is it a problem if the data context of the grid is not explicitly set and it is assumed it will pull from the user control? I tried your solution with no luck, I still get a blank combo box...
Inside the grid the datacontext of evey control is the dataitem of the grid. If you want a different datacontext you need to set it explicitly. In the code below I find the UserControl that is hosting grid and use a property of its datacontext as an itemssource:
<igDP:Field Name="TYPE" Label="Rule Type"> <igDP:Field.Settings> <igDP:FieldSettings> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.RuleTypes}"></Setter> <Setter Property="Value" Value="{Binding TYPE}"></Setter> <EventSetter Event="SelectedItemChanged" Handler="RuleType_SelectedItemChanged"></EventSetter> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
Hope this helps you.