winform datatable 或datagridview中添加列

Posted on 2017-04-12 15:05  熊先生丶  阅读(355)  评论(0编辑  收藏  举报
 DataGridViewCheckBoxColumn dg = new DataGridViewCheckBoxColumn();
            dg.HeaderText = "选择";
            dg.Width = 50;
            dataGridView1.Columns.Add(dg);

添加  table里直接添加  checkbox

 DataTable dt = new DataTable();
            dt.Columns.Add("文件名");
            foreach (string str in lstr)
            {
                DataRow dr = dt.NewRow();
                dr[0] = 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 = 200;

同理