winform datatable 或datagridview中添加列

时间:2021-05-03 15:06:01
 DataGridViewCheckBoxColumn dg = new DataGridViewCheckBoxColumn();
dg.HeaderText = "选择";
dg.Width = ;
dataGridView1.Columns.Add(dg);

添加  table里直接添加  checkbox

 DataTable dt = new DataTable();
dt.Columns.Add("文件名");
foreach (string str in lstr)
{
DataRow dr = dt.NewRow();
dr[] = str; dt.Rows.Add(dr);
}
DataGridViewButtonColumn button = new DataGridViewButtonColumn();
button.HeaderText = "操作";
button.Text = "单独导出";
button.UseColumnTextForButtonValue = true;
dataGridView1.DataSource = dt;
dataGridView1.Columns.Add(button);
dataGridView1.Columns["文件名"].Width = ;

同理