2
Answers

setting Datagrid.Column type

Photo of j_sen21

j_sen21

17y
7k
1

Hello,

I created a table and then set the source of the table to a datagrid. I need to be able to set a specific columns datatype to CheckBox. You can only set the value of the Table to string, int...so on. Is there a way of accessing the datagridvview colums type  after setting the datasource from the table?

How can I do this?

DataTable layerDT = new DataTable();

layerDT.Columns.Add("Layer");

layerDT.Columns.Add("Visible");

dataGridView1.DataSource = layerDT;

---------------------------------------------------------------------------------------------

I need to add something. Instead of creating a table, I try adding the info directly.

DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();

column.HeaderText = "Visibles";

column.Name = "Visibles";

dgTOC.Columns.Insert(0, column);

But now I am looping through data and I need to set each Checkbox based on a true or false. How do I add a row for each data item in the array and check the checkbox.

For(int i;i<array.length;i++)

{

if(array[0] .toString()=="True")

//set checkbox in datagrid to true and add row.

}

 

Thanks a bunch .

 

 

Answers (2)