BurkDiggler
BurkDiggler

Reputation: 161

Silverlight datagrid rebind entire column

I wanted to add datagrid row indexes to my Silverlight MVVM application so I created an IValueConverter that will take the row object and return it's index. The converter itself is working properly and here's the simple row XAML.

 <sdk:DataGridTextColumn Binding="{Binding Converter={StaticResource RowIndexConverter}}" />

The problem is when I add a new row I have to insert it at the top. This creates a new row at index 0 and pushes all of the other rows down one and their row numbers are not updating. Is there a way I can force it to rebind that entire column?

Upvotes: 1

Views: 346

Answers (2)

user302084
user302084

Reputation: 176

Detach and then reattach the datagrid.itemssource.

Upvotes: 1

ColinE
ColinE

Reputation: 70170

To solve this you should probably add RowIndex to the model which you bind to the DataGrid. Whenever rows are added / removed, update the index for each model item - your DataGrid will then be updated.

Upvotes: 2

Related Questions