Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
830
Binding to ActiveDataItem
posted

Hi, I want that by default Row 0 will be selected if there are rows in the grid, so I'm using Binding of ActiveDataItem with a property in the MainViewModel (I'm using the MVVM template).

(I want that if the grid is empty and a new line is being added then it will be selected)

However it doesn't always work. On some project it works for the first time, but after a new list is being created then no row is selected although an ActiveDataItem was set.

I've decided to write a small example to show the problem, but in this case Row 0 is never being selected when the collection is being initialized.

I've attached the example solution.

Run it. Now go to the menu and click on New.

As you can see, the "New" creates a new List<SomeClass> and when the first item is being added then the Active Item is being selected as the item on Index 0.

You can see that the labels on the top bind well to the CurrentSomeClass properties.

However, the grid does not select any row.

 

I think that this is because the ActiveDataItem property is being set before the row was actualy added to the GUI.

 

If I would for example add all 3 rows and then set the CurrentSomeClass to be item 0 then it works.

 

If it wrong to do that I'm doing in the code?

SelectingActiveDataItem.rar