Hi,
I have a c# class which has two properties. One is a string and another is a List object as defined below.
public class MyClass
{
public string Name {get; set;}
public List<string> Cities {get;set;}
}
I want to display the Name property in a column of the datagrid and the list property as a combobox. I'm using MVVM pattern for my development so please advise which is the best way to show these two columns in a datagrid which conforms to the MVVM standards.
Thanks,
Ranjith
Hi Ranjith,
Attached is a sample application so you can check it out. Let me know if you have any questions on the sample.
Best regards,
Vlad
Hi Vlad,
How do you get the same functionality with the list of cities stored on the viewmodel instead of on the class.
Thanks,Femke
Found it, where SearchFields is a collection in the viewmodel:
In a combo:
<ComboBox ItemsSource="{Binding Path=SearchFields}"></ComboBox>
In a xamdatagrid on a usercontrol:
<igDP:XamDataGrid Theme="Aero" IsSynchronizedWithCurrentItem="True" DataSource="{Binding Path=SearchRulesView}" ActiveDataItem="{Binding Path=SearchRule}">
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields>
<igDP:UnboundField BindingPath="Field" BindingMode="TwoWay">
<igDP:UnboundField.Settings>
<igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}">
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamComboEditor}">
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SearchFields}"/>
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:UnboundField.Settings>
</igDP:UnboundField>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>