This is a migrated thread and some comments may be shown as answers.

SelectedItems Collection Shows Incorrect Count

1 Answer 35 Views
GridView
This is a migrated thread and some comments may be shown as answers.
WILLIAM
Top achievements
Rank 1
WILLIAM asked on 15 May 2013, 09:37 PM
I have a property for another control that is based on whether or not there are any SelectedItems in a grid.  When I initially set the Items to the datasource, the SelectedItems collection contains the first row.  Consequently, property is being set incorrectly.  Not only that, but the row is not  even selected in the grid visually.  This to me is incorrect behavior.

I would think the expected behavior to be:

1. Set the DataSource -> SelectedItems = 0
2. Select one or more rows in the grid -> SelectedItems = however many rows were selected.

What property do I need to check that will contain the count of rows that have been selected by the user, and show 0 if nothing has been selected?  I'm already aware of the SelectionChanged event and I'm using it, but the grid in the codebehind does not match the state of the grid being displayed to the user.

??

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 16 May 2013, 09:58 AM
Hi WILLIAM,

In order to prevent from automatically selecting the first GridView's row you can set GridView's property - IsSynchronizedWithCurrentItem to False. For your convenience, I have attached a sample project. As you can see, when IsSynchronizedWithCurrentItem is True then the first row is always selected. You can check the number of selected rows by clicking "Get selected items" button.

I hope this helps.

All the best,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
WILLIAM
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or