Hi,
my xamgrid contains some columns and child columns:
<ig:TextColumn /><ig:TextColumn /><ig:ColumnLayout > <ig:ColumnLayout.Columns><ig:TextColumn /> <XamGridColumns:XamComboEditorColumn />
If i collapse and expand the parent row again the content of the XamComboEditorColumn changes. The other columns keep their content, the cells within the XamComboEditorColumn exchange their content as mentioned. AdjustDisplayElement is called twice for each cell.
Please help, thanks.
I tried with the ComboBox column that Devin supplied in his post, and the values don't "change" nothing happens.
What exactly do you mean by they change?
Can you attach your sample?
Thanks,
-SteveZ
Change means
ParentRow
TextColumn CustomComboBoxColumn
Row1 TestX SelectedItem_X
Row2 TestY SelectedItem_Y
After collapsing and re-expanding
Row1 TestX SelectedItem_Y
Row2 TestY SelectedItem_X
Do you tried it with the attached project? It is a little bit crippled because it exceeded 200 kb, so i had to shorten it.
Thanks for the sample.
So there are a few reasons why you're seeing strange behavior.
1. You don't have a property that stores the SelectedItem for your data. So in this example, your Car class needs to have a SelectedEquipment property, and thats the property that the ComboBoxColumn should be used fore:
public class Car
{
public string Name { get; set; }
public Equipment SelectedEquipment { get; set; }
public ObservableCollection<Equipment> Equip { get; set; }
}
<igcc:ComboBoxColumn Key="SelectedEquipment" DisplayMemberPath="SeatName" Width="200" IsReadOnly="True" />
2. In the ResolveDisplayElement you're setting the Source of the selectedItemBinding to be the row's data. When you shouldn't set the the source, b/c that element will be recycled, and the data will be stuck, which is why you're seeing the alternating values when you collapse and expand. And actually, you shouldn't be creating your own binding at all, and should be using the passed in binding of the method:
this._combobox.SetBinding(ComboBox.SelectedItemProperty, cellBinding);
3. Finally, you're ignoring the ItemsSource property on the column and creating your won in ResolveDisplayElement. What this means, is that every time the the element is recycled, it will resolve the SelectedEquipment property as null, b/c the Equipment that is selected will actually be a different object than the ItemsSource being used. So, you need to ditch the following code, and use the ItemsSOurce off of the column:
// Get Rid of this:
List<ComboBoxColumnDemo.Equipment> equipments = new List<ComboBoxColumnDemo.Equipment>();
Random c = new Random();
equipments.Add(new ComboBoxColumnDemo.Equipment() { SeatName = "LighteningSeat" + (c.Next() % 10), WheelName = "LighteningWheel" });
equipments.Add(new ComboBoxColumnDemo.Equipment() { SeatName = "LighteningSeat" + (c.Next() % 10), WheelName = "LighteningWheel2" });
equipments.Add(new ComboBoxColumnDemo.Equipment() { SeatName = "DocSeat" + (c.Next() % 10), WheelName = "DocWheel" });
equipments.Add(new ComboBoxColumnDemo.Equipment() { SeatName = "DocSeat" + (c.Next() % 10), WheelName = "DocWheel2" });
this._combobox.SetValue(ComboBox.ItemsSourceProperty, equipments);
// Use this:
this._combobox.SetValue(ComboBox.ItemsSourceProperty, column.ItemsSource);
Thanks for your reply, i changed everything but it still doesn't work.
Sorry, i left out one thing, you'd need to make the CellBinding.Mode = twoWay:
cellBinding.Mode = BindingMode.TwoWay;
I've also attached the modified sample:
It works now! Thank you! The problem was, that i created my own binding and didn't used the original cellBinding.
Do we have a resolution to bind the ItemSource of the Combobox column to a child list/property of the view model? I am trying to use a Combbox column in a similar scenario.
Deepa
One thing is a bit ugly about the solution.
If you catch the event for the selection changing in the comboboxes it will be called several times with partly "wrong" data.
it works finally, thank you very much!
Ok, so comboBox and listBox can a bit of a pain to bind to in a recycling scenario, b/c SelectedItem and ItemSource are tied together.
So, when you kill the DataContext for a row, which is expected b/c it's being recycled, the binding says, that the SelectedItem must not be valid anymore, and sets it to null.
So.. with that said, you'll have to move some code around.
First store off the cell binding in ResolveDisplayElement:
_cellBinding = cellBinding;
Then move all your SetBinding logic to AdjustDisplayElement, like so:
public override void AdjustDisplayElement(Cell cell)
ComboBoxColumn column = (ComboBoxColumn)cell.Column;
this._combobox.ClearValue(ComboBox.SelectedItemProperty);
Binding b = new Binding();
b.Source = cell.Row.Data;
b.Path = new PropertyPath(column.ItemSourceMemberPath);
this._combobox.SetBinding(ComboBox.ItemsSourceProperty, b);
this._combobox.SetBinding(ComboBox.SelectedItemProperty, _cellBinding);
base.AdjustDisplayElement(cell);
Now, everything should work as expected.
I think the problem is, that the underlying content of a row is cleared after it is collapsed. Thats the reason why null is stored to SelectedEquipment. Therefore it is empty after expanding again. Is it possible to keep the content of the row?