I have a couple of questions.
i want to use the same xamdatagrid for several different data sources. The reason is that only a few data columns differ. The others are the same. instead of defining two different data grids in xaml and styling the columns there I use the same one and I style the fields in the code behind. So I have
private void OnFieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e) {
if(gridtype1){
var vgDownStyle = new Style(typeof(XamComboEditor)); vgDownStyle.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, new DynamicResourceExtension("ValveGroupList1")));
vgDownStyle.Setters.Add(new Setter(XamComboEditor.DisplayMemberPathProperty, new DynamicResourceExtension("ValveGroupName")));
e.FieldLayout.Fields["VG"].Settings.EditorStyle = vgDownStyle;
}else if (gridtype2) {
var vgDownStyle = new Style(typeof(XamComboEditor));vgDownStyle.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, new DynamicResourceExtension("ValveGroupList2")));
e.FieldLayout.Fields["ValveGroupList2"].Settings.EditorStyle = vgDownStyle;
}
is the above code the same as
<ComboBox Grid.Row="1 ItemsSource="{Binding ValveGroupList1}" DisplayMemberPath="ValveGroupName">
In terms of the bolded text?
If so it's not binding.
second question is (in the same event method as above)
If I have a loop
foreach (var field in e.FieldLayout.Fields) {
is there a way to loop only through fields that contain a specific character?
Thanks
Hi Kris,
You code looks good but just in case this looks like a reference you need in case I’m missing something in your code snippet.
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamComboEditor_Setting_the_xamComboEditor_as_an_Editor_of_a_Field_Programmatically.html
This is the equivalent xaml code for comparison:
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamComboEditor_Using_xamComboEditor_to_Edit_a_Field_in_xamDataGrid.html
I just noticed one thing. Are you binding to a XamComboEditor or have you added a template with a ComboBox to the field? Your OnFieldLayoutInitialized code references the XamComboEditor but the xaml appears to be a ComboBox.
As for your second questions, perhaps you could use linq to create a collection of the specific fields/items you want to review and then loop thru those and reference the specific fields you were interested in (i.e. e.FieldLayout.Fields[fieldname] once you know the name of the field).
Thanks for your suggestion. From the examples provided this is what I have:
In my view model:
public List<string> NorthValveGroupList { get { return _northValvegGroupList; } set { Set(() => NorthValveGroupList, ref _northValvegGroupList, value); } }
in my code behind:
var vgListStyle = new Style(typeof(XamComboEditor)); var vgListSetter = new Setter(XamComboEditor.ItemsProviderProperty, FindResource("NorthValveGroupListKey")); vgListStyle.Setters.Add(vgListSetter); e.FieldLayout.Fields["VG"].Settings.EditorStyle = vgListStyle; e.FieldLayout.Fields["VG"].Width = new FieldLength(55);
in my xaml:
<UserControl.Resources> <igWPF:ComboBoxItemsProvider x:Key="NorthValveGroupListKey" ItemsSource="{Binding NorthValveGroupList}" DisplayMemberPath="ValveGroupName" />
</UserControl.Resources>
but it's still not binding. The data context is set correctly since my xamGridView properly binds and I can see data but not the XamComboBox. If I debug my code I can that NorthValveGroupList get's populated.