I have a datagrid bound to an ObservableCollection of objects. I want to show the index in the first column of the grid. There's numerous example on how to do this based on the LoadingRow event but I need my index to be dynamic - they can add items and remove items from the ObservableCollection so it's easiest if I can bind directly to the ObservableCollection index somehow as this would automatically update in these cases.
I can't figure out how to do this - my classes look something like this:
public class Blindset : INotifyPropertyChanged
{
public ObservableCollection<Blind> Blinds { get; set; }
}
public class Blind : DataChangedNotify
{
public int SmallBlind { get; set ;}
}
Code behind:
gridLevels.ItemsSource = tournament.BlindSet.Blinds;
So if I could somehow bind a column to Blindset.CurrentIndex or IndexOf(currentblind) then it would dynamically update when they added and removed items from the collection without me having to manually reindex them. But each blind row is ignorant of it's parent class (Blindset) so I can't think how to set the templated column to bind to the parent Blindset IndexOf value.
It doesn't seem to make sense putting an index property on the or object and then manipulating it as it is dynamic based on the order.
It's just a cosmetic column - another way I was thinking of was going through each row whenever an add/delete took place and updating the row number, but the binding solution seemed like a better idea if it could be done.
I could ignore the bound object and just use the grid row index somehow, but it needs to be dynamic and update on add and deletes or rows.
There is no sorting/paging on the grid (it's always in the order they add to the collection).
I might be completely off track - any ideas please?