HI,
Can I get a basic sample of using xamComboEditor with xamDataGrid 7.2 ?
Say, I have a table: ClientID / ClientName / CountryID
and I want a combo related to the Countries table: CountryID / CountryName
What is the simpliest way to get it work ?
tbeaulieu said:After slugging through this for a while and with the help of some other postings, I got this working. Here's my solution: Notes: 1. DataContext points to a ModelView, which has a MultumRoute property (IList) that contains the lookup values.2. Domain:MultumRoute is my domain object. The ugliest thing that I had to do here was override the ToString() in this object, which is used when displaying the object in the grid. I didn't know how to specify which property to display. The DisplayMemberPath is used in the actual ComboBox, but once selected, the ToString() is used when the object's in the grid. There's got to be a better way to do that, like with a template? <igDP:FieldLayout.Fields> <igDP:UnboundField Name="MultumRouteName" BindingPath="MultumRoute" Label="Route"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igDE:XamComboEditor}" > <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igDE:XamComboEditor}"> <Setter Property="DisplayMemberPath" Value="Name" /> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}},Path=DataContext.MultumRoutes, Mode=OneWay}" /> <Setter Property="ValueType" Value="{x:Type Domain:MultumRoute}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:UnboundField>
After slugging through this for a while and with the help of some other postings, I got this working. Here's my solution:
Notes:
1. DataContext points to a ModelView, which has a MultumRoute property (IList) that contains the lookup values.2. Domain:MultumRoute is my domain object. The ugliest thing that I had to do here was override the ToString() in this object, which is used when displaying the object in the grid. I didn't know how to specify which property to display. The DisplayMemberPath is used in the actual ComboBox, but once selected, the ToString() is used when the object's in the grid. There's got to be a better way to do that, like with a template?
<igDP:FieldLayout.Fields>
<igDP:UnboundField Name="MultumRouteName" BindingPath="MultumRoute" Label="Route"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igDE:XamComboEditor}" > <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igDE:XamComboEditor}"> <Setter Property="DisplayMemberPath" Value="Name" /> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}},Path=DataContext.MultumRoutes, Mode=OneWay}" /> <Setter Property="ValueType" Value="{x:Type Domain:MultumRoute}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:UnboundField>
This worked for myself as well. But I did one thing a little different. Instead of overiding the ToString(), I overrode the Equals(). This way it can compare by ID instead of by HashCode.
Example:
public partial class Lookup{
public Guid LookupID { get { return lookupID; } set { this.lookupID = value; } }
public string DisplayText { get { return displayText; } set { this.displayText = value; } }
public override bool Equals(object obj) { if (obj is Lookup) return Equals(obj as Lookup); else return false; } public bool Equals(Lookup lookup) { return LookupID.Equals(lookup.LookupID); }
}
¿Cut you please post some of you C# code? I have a coupple of doubts here, 'cause if I set DataContext property and I set AutoGenerateFields= False no rocrods are shown.
I got this sample to work, but - as always - there's a catch. My child object doesn't use an ID as the FK to the parent. Instead, it has a pointer to the parent object. Therefore, I don't know how to get the combo to persist the selected parent into the child row.
The code below shows me using a standard ComboBox with a similar situation.
Is there a workaround for a ComboBox in a xamgrid?
Thank you.
<ComboBox Name="DrugTypeField" Grid.Row="2" Grid.Column="1" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=DrugTypes}" SelectedItem="{Binding Path=CurrentMasterEntity.DrugType, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}" DisplayMemberPath="Name" />
Hi,
You can do something like below. Set the Field's EditorType to XamComboEditor and specify a style that binds to the list that contains country ID's and names. Set the ItemsProvider of the XamComboEditor to the list that actually does the mapping. In code below, the list is being created in code in the constructor of the window:
<dg:XamDataGrid x:Name="dp" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" > <dg:XamDataGrid.FieldLayouts> <dg:FieldLayout IsDefault="True"> <dg:FieldLayout.Fields> <dg:Field Name="ID"> <dg:Field.Settings> <dg:FieldSettings EditorType="{x:Type dge:XamComboEditor}" > <dg:FieldSettings.EditorStyle> <Style TargetType="{x:Type dge:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{DynamicResource ComboEditorList}"/> </Style> </dg:FieldSettings.EditorStyle> </dg:FieldSettings> </dg:Field.Settings> </dg:Field> </dg:FieldLayout.Fields> </dg:FieldLayout> </dg:XamDataGrid.FieldLayouts> </dg:XamDataGrid>
{
InitializeComponent( );
dt.Columns.Add(
dt.Rows.Add(
ip.ItemsSource = dt.DefaultView;
ip.ValuePath =
Hope this helps,