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

Dynamically bind item source with dynamic field?

3 Answers 83 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Woramin
Top achievements
Rank 1
Woramin asked on 16 Sep 2011, 04:49 AM
Hi.

I would like another help again

According to binding item source procedure what I have been looking in your Telerik's demo. For example, it should be some kind like....

=============================================================

1. Create class that contains properties with {get; set;}. No. of properties/fields should be depend on which fields we want to bind
such as...

public class Employee
{
      public string Id {get; set;}
      public string Name {get; set;}
      public string Position {get; set;}
}

2. Create the collection such as List<>,ObservableCollection<> that will contain the item in each field such as...

ObservableCollection<Employee> empList = new ObservableCollection<Employee> ();
empList.Add(new Employee(){Id = '1', Name ='AAA', Position = 'A1A1'});
empList.Add(new Employee(){Id = '2', Name ='BBB', Position = 'B1B1'});

3. Set the item source with that collection for the RadGridView and the directly set binding to each field for display columns such as...
    (I set the itemsource in the code behind)

<telerik:RadGridView  x:Name="RadGridView1">
      <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Header="ID" DataMemberBinding="{Binding ID}" />
            <telerik:GridViewDataColumn Header="Employee Name" DataMemberBinding="{Binding Name}" />
             <telerik:GridViewDataColumn Header="Position" DataMemberBinding="{Binding Position}"  />
       </telerik:RadGridView.Columns>
</telerik:RadGridView>


======================================================================================

Right??

Then the question is, if I want other RadGridViews that display some columns  which might be somewhat (or entirely) different from first RadGridView (For example, create another GridView that also display Employee data similarly to the first one but with additional column called "Department", then another GridView but at this time with the column called "Address"). In order to create such an item source with the class, do I need to create another class with some different field again and again?

At this time, what I have done is create class with all fields that some columns might be appeared in every grid but some columns might not be appeared in some grid, create collection with data adding to specified field for each grid then binding that grid with specific field.

Is there anyway better than what I'm doing to create item source by just creating only one class or other methods  that can create List<> or ObservableCollection<> with dynamically field?


If you don't understand what I'm trying to say please let me know.

Thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 21 Sep 2011, 08:16 AM
Hi,

 I'm not sure if you've seen our Silverlight DataTable however may help you in your scenario. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Woramin
Top achievements
Rank 1
answered on 22 Sep 2011, 02:24 AM
Hi, Vlad

I will try implementing this to my project. If any problem, I will report you here.

Thanks
0
Woramin
Top achievements
Rank 1
answered on 26 Sep 2011, 04:22 AM
Hi there again, Vlad

I would like to inform you that your data table works great. This surely helps me a lot to eliminate the constraint of binding datasource from the class with the specific field inside. At this time, I haven't discovered any error from your silverlight data table. I hope it will work fine to my overall project.

Thanks again for your help.
Tags
GridView
Asked by
Woramin
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Woramin
Top achievements
Rank 1
Share this question
or