Hi,
I have a datagrid with a few rows.
Each row has a different Part (as in Part from a Car). Depending on the Part the ComboBox values have to be different.
So if I select the Part Wheel the Combobox values have to be something like (Piece, Crate).When I select the Part Cable the Combobox values have to be something like (Meters, Box).
With the code provided I can set the values with a style, but the last set style is leading for every Combobox. The last style overwrites every style set earlier.
What am I doing wrong? How can I give each new row new ComboBox values?
Here is the code:
dataGrid.InitializeRecord += new EventHandler<Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs>(dataGrid_InitializeRecord);
private void dataGrid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e) { DataRecord dr = e.Record as DataRecord; if (dr != null) { foreach (Cell cell in dr.Cells) { if (cell.Field.Name.ToString() == "UNITCONVERTERID") { UnitConverter unitConverter = UnitConverterManager.GetNewUnitConverter(); ComboBoxItemsProvider lookUpItems = new ComboBoxItemsProvider(); XamComboEditor xamComboBox = sender as XamComboEditor; BizObj bizObj = GetBizObjFromDataRecord(dr); if ((bizObj != null) && (bizObj.GetType() == typeof(HourCostLine)) && ((bizObj as HourCostLine).ItemObj != null)) { if (bizObj.ID == 1) { unitConverter.Unit = "Pieces"; unitConverter.ID = 0; // a unique ValueList lookUpItems.DisplayMemberPath = "Unit"; lookUpItems.ValuePath = "ID"; lookUpItems.Items.Add(unitConverter); Setter setter = new Setter(); setter.Property = XamComboEditor.ItemsProviderProperty; setter.Value = lookUpItems; // Add the setter to the style and assign to this field Style style = new Style(typeof(XamComboEditor)); style.Setters.Add(setter); cell.Field.Settings.EditorStyle = style; } else { unitConverter.Unit = "Meters"; unitConverter.ID = 1; // a unique ValueList lookUpItems.DisplayMemberPath = "Unit"; lookUpItems.ValuePath = "ID"; lookUpItems.Items.Add(unitConverter); Setter setter = new Setter(); setter.Property = XamComboEditor.ItemsProviderProperty; setter.Value = lookUpItems; // Add the setter to the style and assign to this field Style style = new Style(typeof(XamComboEditor)); style.Setters.Add(setter); cell.Field.Settings.EditorStyle = style; } } } } } }
Thanks in advance,
Patrick
is it possible to look at my question above?
Am I clear enough in what I want to accomplish?
thanks in advance!
Hello Patrick,
I apologize for not getting to this post earlier.
The code snippet is pretty close to what a working solution would be. The issue is that you are assigning the style to the Field.Settings.EditorStyle. This will indeed set this style to all of the editors. What you need to do is to actually set this to the Editor.Style. You have access to the editor through the CellValuePresenter or the cell (Cell.EditorStyle).
Moreover, I unearther an old sample with cascading XamComboEditors in the XamDataGrid using MVVM. Perhaps you might be interested in going over the sample code.
Hi Alex,
thanks for your response.
My apologies for the delay, your reaction ended up in my Spambox so I didn't see it earlier.
I'm going to look at your example and try the code.
I'll be back.
grtz Patrick
Hello Support Team,
I have question on the above sample application. On application startup when a user selects a category how to automatically default to the first item in the Name field?
Alex,
it works!!
Thanks.
this is the code if anybody is interested:
private void dataGrid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e) { DataRecord dr = e.Record as DataRecord; if (dr != null) { foreach (Cell cell in dr.Cells) { if (cell.Field.Name.ToString() == "UNITCONVERTERID") { ComboBoxItemsProvider lookUpItems = new ComboBoxItemsProvider(); XamComboEditor xamComboBox = sender as XamComboEditor; BizObj bizObj = GetBizObjFromDataRecord(dr); lookUpItems.ItemsSource = UnitConverterManager.GetUnitConverterCollectionByItemID(Item); lookUpItems.DisplayMemberPath = "Unit"; lookUpItems.ValuePath = "ID"; Setter setter = new Setter(); setter.Property = XamComboEditor.ItemsProviderProperty; setter.Value = lookUpItems; // Add the setter to the style and assign to this field Style style = new Style(typeof(XamComboEditor)); style.Setters.Add(setter); cell.EditorStyle = style; } } }