I have 2 xamcomboeditors in my Grid and selected item of first should pass as a string parameter to ObjectDataProvider of second. How to bind the selected item of first to method parameter of object data provider of second
<ObjectDataProvider x:Key="dbNames" MethodName="GetName" ObjectType="{x:Type myApp:NameList}" > <ObjectDataProvider.MethodParameters> <x:Static Member="sys:String.Empty" /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider>
<ObjectDataProvider x:Key="dbSNames" MethodName="GetSName" ObjectType="{x:Type myApp:SNameList}" > </ObjectDataProvider>
<ig:XamComboEditor x:Name="cmbBrowse" Height="20" Width="100" Padding="3,2" Margin="10 0 0 0" IsEditable="True" AllowFiltering="True" AutoComplete="True" OpenDropDownOnTyping="False" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Row="1" ItemsSource="{Binding Source={StaticResource dbSNames}}"> </ig:XamComboEditor> <ig:XamComboEditor Name="cmbName" Height="20" Width="180" Padding="3,2" AllowMultipleSelection="False" IsEditable="False" Grid.Row="2" ItemsSource="{Binding Source={StaticResource dbNames}}" Margin="0 0 300 0"> </ig:XamComboEditor>
Code Behind:
public class NameList { public ObservableCollection<TypeList> GeName(string name) { if (!string.IsNullOrEmpty(servername)) { ObservableCollection<string> lst = Program.GetCollectionFromDataset(Program.GetName(name)); if (lst == null) return new ObservableCollection<TypeList>(); else { ObservableCollection<TypeList> cst = new ObservableCollection<TypeList>(); foreach (string s in lst) { cst.Add(new TypeList(s)); } return cst; } } else return new ObservableCollection<TypeList>(); } }
public class SNameList { public ObservableCollection<TypeList> GetSName() { ObservableCollection<string> lst = Program.GetCollectionFromDataset(Program.GetSName()); if (lst == null) return new ObservableCollection<TypeList>(); else { ObservableCollection<TypeList> cst = new ObservableCollection<TypeList>(); foreach (string s in lst) { cst.Add(new TypeList(s)); } return cst; } } } #endregion
public class TypeList { public string fieldOptions { get; set; } public TypeList() { fieldOptions = null; } public TypeList(string a) { fieldOptions = a; } }
Hi hlhz,
I don't see where you set the DisplayMemberPath. Are you setting this? If you are not setting the DisplayMemberPath then the XamComboEditor is not going to know which property inside WpfApplication1.TypeList that you want to use as the display text and it will just show the full class name.
Hello I am following up on this above attached example. Using the same code in example but in XamComboEditor in XamDataGrid row. Instead of seeing the string
"option A", "option B", "option C"
I see WpfApplication1.TypeList. How can i convert it to string?
<igDP:XamDataGrid Name="dataCompGrid" AutoFit="True" Grid.Row="0" Grid.RowSpan="2" GroupByAreaLocation="None" DataSource="{Binding}" BindToSampleData="False"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AllowFieldMoving="WithinLogicalRow" AutoGenerateFields="False" HighlightAlternateRecords="True" AllowClipboardOperations="Copy"></igDP:FieldLayoutSettings> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="Cusip" Label="Cusip" ToolTip="Cusip ID" FixedLocation="FixedToNearEdge" /> <igDP:UnboundField BindingPath="CollatType" Label="Collat Type" ToolTip="Select Collat Type" BindingMode="TwoWay"> <igDP:UnboundField.Settings> <igDP:FieldSettings> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider"> <Setter.Value> <igEditors:ComboBoxItemsProvider ItemsSource="{Binding Source={StaticResource dbNames}}" /> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:UnboundField.Settings> </igDP:UnboundField> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Here is the sample I used to test this. Let me know if you have any questions on this.
The first thing you need to do is modify the parameters your GetName method accepts. Right now you take in a string but since you bind the comboeditor to a collection of TypeList the SelectedItem property of the editor is going to return a TypeList object. So modify your GetName method to accept a TypeList object instead of a string and then alter the XAML for the method parameters.
<ObjectDataProvider x:Key="dbNames" MethodName="GetName" ObjectType="{x:Type myApp:NameList}" > <ObjectDataProvider.MethodParameters> <x:NullExtension/> </ObjectDataProvider.MethodParameters> </ObjectDataProvider>
Now add this XAML to the comboeditor:
<ig:XamComboEditor.SelectedItem> <Binding Source="{StaticResource dbNames}" Path="MethodParameters[0]" BindsDirectlyToSource="True"/> </ig:XamComboEditor.SelectedItem>
When you select a value from this comboeditor, it will update the SelectedItem property which will then update the method parameters for the object data provider.