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

How to get selectedIndex of the gridview

4 Answers 673 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Max xu
Top achievements
Rank 1
Max xu asked on 27 Mar 2010, 02:46 AM
How to get selectedIndex of the gridview

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 29 Mar 2010, 07:12 AM
Hi,

You can use SelectedItem to achieve your goal:

var index = RadGridView1.Items.IndexOf(RadGridView1.SelectedItem);

All the best,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Walter
Top achievements
Rank 1
answered on 11 Feb 2014, 11:12 AM
Does not working for me :/ My selected item is on position of 0 and debuger shows

radGridView.SelectedItem.GetHashCode() = X
radGridView.Items[0].GetHashCode() = Y

Obviously in debuger queries

radGridView.SelectedItem
radGridView.Items[0]

shows same object.

Where is the problem?

Regards
Walter
0
Walter
Top achievements
Rank 1
answered on 11 Feb 2014, 01:55 PM
Force bindings update helps in my case:


var selectedItemBindingExpression = radGridView.GetBindingExpression( RadGridView.SelectedItemProperty );
            if( selectedItemBindingExpression != null )
            {
                selectedItemBindingExpression.UpdateTarget();
            }
            var itemsSourceBindingExpression = radGridView.GetBindingExpression( RadGridView.ItemsSourceProperty );
            if( itemsSourceBindingExpression != null )
            {
                itemsSourceBindingExpression.UpdateTarget();
            }
0
Joseph
Top achievements
Rank 1
answered on 23 Sep 2020, 03:06 PM

Thanks! this worked for my application. I originally used RadGridView1.SelectedItems and the index of the selected item was always 0 because I have a single selection list. I though about what I did and was like, duh. It will always be 0 for a single selection list.

Tags
GridView
Asked by
Max xu
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Walter
Top achievements
Rank 1
Joseph
Top achievements
Rank 1
Share this question
or