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
Since a column isn't a FrameworkElement, you can't use a binding with and rely on DataContext inheritance or ElementName bindings, however you can use StaticResource as your Source.
<ig;ComboBoxColumn ItemsSource={Binding Source={StaticResource yourCollection}, Path=yourItemsPropertyName}/>
Thanks!
What should i do, if i have a list within a list within a list. How to bind that?
I need help, asap!
Bye
Could you provide a little more details?
Perhaps an example of how your data is laid out?
sorry. For example:
ObservableCollection<DemoData> Data contains
string PropAdouble PropBObservableCollection<Car> PropC
Car contains
string Name { get; set; }Equipment SelectedEquipmentObservableCollection<Equipment> Equip
and ItemsSource of the XamGrid is Data
How do i bind Eqip to the Column ItemsSource?
Is Equipment going to be different for each Row?
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?
I just took your last sample, followed your instructions and did this
<igcc:ComboBoxColumn Key="SelectedEquipment" ItemSourceMemberPath="Equip" DisplayMemberPath="SeatName" Width="200" IsReadOnly="True" />
public override FrameworkElement ResolveDisplayElement(Cell cell, System.Windows.Data.Binding cellBinding) { ComboBoxColumn column = (ComboBoxColumn)cell.Column; Binding b = new Binding(); b.Source = cell.Row.Data; b.Path = new PropertyPath(column.ItemSourceMemberPath); this._combobox.SetBinding(ComboBox.ItemsSourceProperty, b); if (column.DisplayMemberPath != null) this._combobox.SetValue(ComboBox.DisplayMemberPathProperty, column.DisplayMemberPath); cellBinding.Mode = BindingMode.TwoWay; this._combobox.SetBinding(ComboBox.SelectedItemProperty, cellBinding); this._combobox.Style = cell.EditorStyleResolved; return this._combobox; }
ComboBoxColumn
/// <summary> /// Identifies the <see cref="ItemSourceMemberPath"/> dependency property. /// </summary> public static readonly DependencyProperty ItemSourceMemberPathProperty = DependencyProperty.Register("ItemSourceMemberPath", typeof(String), typeof(ComboBoxColumn), null); /// <summary> /// Gets or sets a collection used to generate the content of the <see cref="ItemsControl"/> /// </summary> public String ItemSourceMemberPath { get { return (String)this.GetValue(ItemSourceMemberPathProperty); } set { this.SetValue(ItemSourceMemberPathProperty, value); } }