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

Using GridView.DataSource and GridViewComboBoxColumn

1 Answer 180 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 11 Dec 2009, 11:08 PM

Hi

 I would like to know how I can use a GridView.DataSource with a GridViewComboBoxColumn.

private DataTable GridVDataSource = new DataTable();
**
**
This.GridView1.DataSource = GridVDataSource;
**
**

// Update GridView1 DataSource

private void button1_Click(object sender, EventArgs e)

{       

    GridVDataSource = " SQL operations ("SELECT StateID FROM State")";
}

However the StateID Column must be a combobox.
How can I change the column type to keep the combobox at each DataSource refresh?

If I created the column before :

private void form1_Load(object sender, EventArgs e)
{
    GridViewComboboxColumn Combo = new GridViewComboboxColumn("StateID","");
    Combo.DataType = typeof(int);

    Combo.DataSource = StateDataSource;   // Loaded before

    Combo.DisplayMember = "StateName";

    Combo.ValueMember = "StateID";

    this.GridViewLanguages.Columns.Add(Combo);
}

 

When I refresh the DataSource (button1_Click) the GridView add the DataSource columns like news columns.

So, how is it possible to keep the initial combobox columns or to change them after loading the column type?

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Victor
Telerik team
answered on 16 Dec 2009, 05:41 PM
Hello Julien,

In order to stop the the grid from generating the columns on each rebind, you just need to set the AutoGenerateColumns property to false after the first time they are generated. For example:

grid.DataSource = yourDataSource;
if (!columnsAlreadyGenerated)
{
    grid.MasterGridViewTemplate.AutoGenerateColums = false;
    columnsAlreadyGenerated = true;
}

 

Write again if you need further assistance.

Sincerely yours,
Victor
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
Julien
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or