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

RadGridView SelectedItem

11 Answers 247 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Karthik
Top achievements
Rank 1
Karthik asked on 01 Mar 2012, 01:12 AM
I have a RadGridView in my silverlight application. It looks like this

<telerikGrid:RadGridView ItemsSource="{Binding Source}"   SelectedItem="{Binding SelectedItem, Mode=TwoWay}">

Source is an IEnumerable on the ViewModel. Everything gets bound properly, when I select an item in the list, the property SelectedItem in the ViewModel gets called.

Sometimes when the page loads, I would like to have a particular row selected.To achieve this I call the setter on SelectedItem programatically, I expect to see the row selected on the UI, but it doesnt seem to happen. (The item that am selecting is one amongst the items in the Source)

Any ideas why?

Thanks
K

11 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 01 Mar 2012, 08:16 AM
Hi,

Please make sure that you've raised PropertyChanged of your model. 

Greetings,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Karthik
Top achievements
Rank 1
answered on 01 Mar 2012, 01:10 PM
Vlad

I do have the propertychanged event raised on my model. Any other ideas?


Thanks
K
0
Vlad
Telerik team
answered on 01 Mar 2012, 01:12 PM
Hi,

 Can you post more info about your version? 

Regards,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Karthik
Top achievements
Rank 1
answered on 01 Mar 2012, 01:16 PM
Vlad,

Am using SIlverlight 4 with Telerik Controls from version 2011.2.712.1040.

Thanks
K
0
Yordanka
Telerik team
answered on 01 Mar 2012, 04:36 PM
Hi Karthik,

Can you give us more details about your implementation - how do you assign the SelectedItem? Which event you are using for doing this? Do you set the property of the view model or the SelectedItem property of RadGridView?
 
Greetings,
Yordanka
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Karthik
Top achievements
Rank 1
answered on 01 Mar 2012, 04:46 PM
Yordanka ,

The SelectedItem is a property on the ViewModel and that property gets assigned a value based on some other event.
It looks as simple as this

public SomeObject SelectedItem {
    get{ return _selectedItem}
    set{
            if(value == null) return;
           _selectedItem = value;
           OnPropertyChanged("SelectedItem")
       }
}


The property seems to work, because when I select an item in the grid, the setter property gets called appropriately.

Thanks
K
0
Maya
Telerik team
answered on 01 Mar 2012, 04:57 PM
Hi Karthik,

Could you verify how do you set the SelectedItem of RadGridView ?  Do you set directly SelectedItem property of RadGridView or you set it through the SelectedItem property of your ViewModel ? 

All the best,
Maya
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Karthik
Top achievements
Rank 1
answered on 01 Mar 2012, 05:25 PM
Was the reply below not sufficient? If it wasn't can you please elaborate what you are asking me. Please bear with my ignorance, am a newbie to all this.

Thanks
K
0
Maya
Telerik team
answered on 02 Mar 2012, 08:35 AM
Hi Karthik,

Do you at any place set SelectedItem similar to:

this.myRadGridView.SelectedItem = this.myRadGridView.Items[1];
 
Or you count entirely on the binding and set the SelectedItem property from your view model:
myViewModelInstance.SelectedItem = myNewSelectedItem;


All the best,
Maya
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Karthik
Top achievements
Rank 1
answered on 02 Mar 2012, 02:03 PM
Maya,

I dont do any work in the code behind (neither I do anything like your code snippet one), all my bindings are happening entirely in the view model. (similar to the the second code snippet you have shown)

Thanks
K
0
Doug
Top achievements
Rank 1
answered on 18 Oct 2012, 01:38 AM
So Maya, did you drop the ball on this user or what? I was eager to read this thread, but when I got to the end and it just aborted, I was disappointed, if not worse.
Doug
Tags
GridView
Asked by
Karthik
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Karthik
Top achievements
Rank 1
Yordanka
Telerik team
Maya
Telerik team
Doug
Top achievements
Rank 1
Share this question
or