Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add column dynamically in datagridview using c#

how to add column dynamically in datagridview using c#

like image 508
ratty Avatar asked Mar 04 '10 07:03

ratty


People also ask

How to add column Dynamically in DataGridView in c#?

On click of start new examination a new column should be added to grid to enter examination data against measurement variable. Same way user can add another new column to record examination details on click of "New examination" button.

How to add TextBox column in DataGridView in c# Dynamically?

TextBox TextBox1 = new TextBox(); GridView1. Rows[0]. Cells[0].

How do I add a column in data grid view?

) on the upper-right corner of the DataGridView control, and then select Add Column. In the Add Column dialog box, choose the Databound Column option and select a column from the data source, or choose the Unbound Column option and define the column using the fields provided.


2 Answers

For example:

        DataGridViewColumn col = new DataGridViewTextBoxColumn();
        col.HeaderText = "Hi there";
        int colIndex = grid.Columns.Add(col);
like image 113
Marc Gravell Avatar answered Sep 25 '22 03:09

Marc Gravell


If it's like any of the other .Net grid controls:

YourDataGridView.Columns.Add(New DataGridViewColumn());
like image 29
ChadT Avatar answered Sep 26 '22 03:09

ChadT