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

[Solved] RadGridView binding to simple collection of strings?

1 Answer 711 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Patrick Holloway
Top achievements
Rank 1
Patrick Holloway asked on 21 Nov 2009, 05:55 PM
Given a simple collection of strings, like this:

 

 

ObservableCollection<string> items = new ObservableCollection<string>();  
for (int i = 0; i < 5; i++) {  
   items.Add(String.Format(itemName + ".Item" + i));  
}  
 

binding to a plain gridview like this:

aGridView.ItemsSource = items; 

gives us a gridview with one column named "Length" and rows populated with the string.Length of the items in the collection.

We can also see this behavior on the Telerik demo page, here:

http://demos.telerik.com/silverlight/beta/#GridView/DataSources

Clicking on the "Simple List" option binds the gridview to a simple list of strings, shown in the example code like this:

List<string> list = new List<string>();  
   foreach (Customer customer in ExamplesDB.GetCustomers())  
   {  
       list.Add(customer.ContactName);  
   }  
 

but again, it does not display a list of customer names, but a column named "Length", and rows populated with string.Length of the items in the collection.

Is this really the desired behavior? What if I actually want to show the strings, and not their length?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 23 Nov 2009, 12:14 PM
Hi Patrick,

Indeed with auto-generated columns you will get this since the grid will try to resolve all public properties of the element type. To handle your scenario you can declare your own column like this:

<telerik:RadGridView ItemsSource="{Binding}">
  <telerik:RadGridView.Columns>
     <telerik:GridViewDataColumn Header="YourHeader" DataMemberBinding="{Binding}"/>
  </telerik:RadGridView.Columns>
</telerik:RadGridView>


Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Patrick Holloway
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or