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

Set selected row/item

1 Answer 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 06 Jun 2010, 10:56 PM
Hi, I would like to set which row gets selected please.

I have this code belwo which is close
this.myGrid.SelectedItem = this.myGrid.Items[nextIndex];

I would imagine the pseudo code would be something like

int CustomerID= 100
this.myGrid.SelectedItem = this.myGrid.Items[CustomerID];

Many thanks

Steven

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 07 Jun 2010, 01:01 PM
Hello Steven,

Your approach is quite correct. However, everything depends on the time you are setting the selected item. The problem here is that when trying to set it in the constructor, the collection is still not created and that's why you cannot define the selected row.
What you can do is to set it in the DataLoaded event. For example:

private bool initialized = false;
void playersGrid_DataLoaded(object sender, EventArgs e)
        {
            if (initialized)
            {
                return;
            }
            this.playersGrid.SelectedItem = this.playersGrid.Items[2]; 
            initialized = true;
        }

Since the DataLoaded event occurs on different scenarios, you can add the variable initialized to ensure that setting of the selected item happens only once. 

You can find more information about Selection in RadGridView in our online documentation.

I hope that helps.

 

All the best,
Maya
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.
Tags
GridView
Asked by
Steven
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or