Silverlight / WPF - To Bind RadGrid dynamically

Asked By Parameswari on 12-Mar-12 07:16 AM
   I using Telerik tool. I need to change my itemsource and selected item of the RadGrid dynamically
   Can any one guide me  how to Bind selected item and Itemsource of the Grid in CodeBehind.
 I posted Support in Telerik ,but they didn't reply me properly. Its urgent, Please guide me..

Thank You
D Company replied to Parameswari on 12-Mar-12 10:48 AM
Simplest way changing the dynamically item source is like this,

this.YourGridName.ItemsSource = //here assign your item source.

a similar post i have seen here , it will help you see this

Let me know if it is not helpful.

[)ia6l0 iii replied to Parameswari on 12-Mar-12 01:50 PM
Here is one way to do this in Silverlight. 

First of all, create a ObservableCollection that contains the data.  Let's say for e.g. you need to bind the list of employees to the RadGrid. 
public ObservableCollection<Employee> Employees
{ get { ; } set { ; } }

Bind the Radgridview itemssource to the observable collection in the markup.
<telerik:RadGridView x:Name="rgvEmployees"  ItemsSource="{Binding Employees}">

Fill up the observable collection from your datasource. Let's assume that the data is in the following format. 
Employees = new Employee[] { };
Employees.Add(new Employee{
//the values });
Employees.Add(new Employee{
//the values });

... and so on. 

Add the data to the dataContext
this.DataContext = this;

That's it. This is about binding the radgridview to data. 

For selected, set the SelectedItem to a binding value something like below: The following line of code selectes the 10th row for example.
rgvEmployees.SelectedItem = rgvEmployees.Items[10];

And if you do this via markup following is the way.
SelectedItem="{Binding SelectedTeam, Mode=TwoWay}"

Hope this helps.
Parameswari replied to [)ia6l0 iii on 13-Mar-12 03:22 AM

   Thank you, I solved the Problem ..
[)ia6l0 iii replied to Parameswari on 13-Mar-12 07:31 AM
Glad to help!