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,
I believe you need to bind the XamComboEditor's ItemsSource to the DataTable.DefaultView. Like the XamDataGrid, you can't bind directly to the DataTable. So you might want to make your ValveGroupStatusCodes property a DataView instead and when you set it's value, set it to your DataTable.DefaultView.
I do have one more question. I need to bind a data table to this xamComboEditor. From you two suggestions I chose to bind the data in the xaml
<Style x:Key="VGStatusCodesStyle" TargetType="{x:Type igWPF:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.ValveGroupStatusCodes}"/></Style>
How would I change the syntax to it displays a data table?
Thanks for the sample. From it I was able to tell what the issue was.
The Binding code I sent you was more of an example rather than the definitive code you need to use. In the case of your sample, the Binding needs to use RelativeSource to go up to the Window and then bind to the DataContext.ComboList property. I've attached a modified version of your sample with the changes.
Hello. Unfortunately it's still not working. I've attached a small sample project. Please have a look. Your help is greatly appreciated.
ComboBoxItemsProvider does not have a DataContext so binding to the ItemsSource property like that is not going to work. You should bind your NorthValveGroupList directly to the XamComboEditor's ItemsSource property instead. You can set the value in the Setter constructor to a Binding rather than assigning the collection directly.
Style style = new Style(typeof(XamComboEditor));
style.Setters.Add(new Setter(XamComboEditor.ItemsSourceProperty, new Binding("NorthValveGroupList")));