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

[Solved] Add Column dynamically?

3 Answers 177 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.
Alessandro
Top achievements
Rank 1
Alessandro asked on 12 Nov 2010, 07:43 PM
Given the following class types

public class Stuff
{
   public bool IsSelected {get; set;}
   public string School {get; set;}
}

public class Person
{
   public string FName {get; set;}
   public string LName {get; set;}
   public object Data {get; set;}  // an instance of Stuff will be assigned here.
}

1. I am binding to a collection of persons.
2. I have no templates defined for my columns. I will auto generate columns.

3. I need the grid to display the following columns

IsSelected, School, FName, LName

So I need to be able to dynamically add the columns, set there binding and types so that the user can check/uncheck IsSelected. However, I can add the column but only the text "False" shows as the value. Here's how I add the column. Certainly, I'm missing some pieces. Any ideas?

            GridViewDataColumn gvdc2 = new GridViewDataColumn();
            gvdc2.DataMemberBinding = new System.Windows.Data.Binding("Data.IsSelected");
            gvdc2.DisplayIndex = 2;
            SearchResultsGrid.Columns.Add(gvdc2);

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 15 Nov 2010, 09:24 AM
Hello Xavier,

You could try using our CheckBox column which might be a better fit for your particular scenario:

GridViewCheckBoxColumn gvdc2 = new GridViewCheckBoxColumn();
gvdc2.DataMemberBinding = new System.Windows.Data.Binding("Data.IsSelected");
gvdc2.DisplayIndex = 2;
SearchResultsGrid.Columns.Add(gvdc2);


Kind regards,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alessandro
Top achievements
Rank 1
answered on 15 Nov 2010, 04:23 PM
Thanks Milan, that is helpful! 

Is there a list of the types of columns I can generate? I'm not seeing this in the documentation anywhere. Thanks!

 -- xavier
0
Veselin Vasilev
Telerik team
answered on 15 Nov 2010, 05:23 PM
Hi Xavier,

In the documentation of RadGridView there is a node Column. There you will find a lot of articles about the gridview's columns. There is a section Column Types as well - there you can find all the column types you can use. Please start from here.

Regards,
Veselin Vasilev
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
Tags
GridView
Asked by
Alessandro
Top achievements
Rank 1
Answers by
Milan
Telerik team
Alessandro
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or