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

SelectedItems Not Working

1 Answer 70 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frustrated Dev
Top achievements
Rank 1
Frustrated Dev asked on 01 Dec 2010, 05:20 PM
Hello,

I am using the RadGridView control to allow a user to select one or more items. In certain cases, a user will select one row in the grid. To accomplish this, I have set the "SelectionUnit" property to "FullRow". To respond accordingly to the user's interaction, I have written an event handler for the SelectionChanged event. This is where my problem comes in.

In the case that the user has selected a single row, I want to get the ID for that object. I am doing this using the following code:
private void myGridView_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
{
  RadGridView gridView = (RadGridView)(sender);
  if (gridView.SelectedItems.Count == 1)
  {
    MyProxy.MyClass selectedItem = (MyProxy.MyClass)(gridView.SelectedItem);
    MessageBox.Show(selectedItem.ID.ToString());
  }
}

The first time I select a row in the grid, the ID displays properly. However, on following attempts, the previously selected id is selected. I've noticed that if I select the same row twice, the correct ID appears on the second attempt.

What am I doing wrong? How do I get the id of the currently selected item in the grid?

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 05 Dec 2010, 09:27 PM
Hello Frustrated Dev,

I couldn't reproduce this issues. Could you please try to reproduce it with the attached sample?


Kind regards,
Milan
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Frustrated Dev
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or