winform中怎样使DataGridView的某一列可以添加两个Button控件

winform中怎样使DataGridView的某一列可以添加两个Button控件,第1张

在dataGridView控件的属性里有一个叫做Columns的属性,旁边有一个上面写着两个省略号的按钮(..),点一下(也可以点击控件右上角小三角形,选编辑列),出来一个对话框,左侧一栏里有一个TemplateField,选中,然后点击添加,然后点右下角的确定。然后在dataGridView控件上右键选编辑模板,然后选columns[]([]中的数字代表你刚才添加的模板列是第几列)然后在TemplateField中添加两个RadioButton控件,然后右键结束模板编辑就可以了。

添加Data GridView Button Column。

具体代码如下:

public Form1()

{

InitializeComponent()

this.Load += new EventHandler(Form1_Load)

}

List<string>strSourec = new List<string>{ "1", "2" }

void Form1_Load(object sender, EventArgs e)

{

foreach (string item in strSourec)

{

DataGridViewButtonColumn Column1 = new DataGridViewButtonColumn()

Column1.HeaderText = item

this.dataGridView1.Columns.Add(Column1)

}

DataGridViewRow dr = new DataGridViewRow()

for (int i = 0i <strSourec.Counti++)

{

DataGridViewButtonCell dgvbc = new DataGridViewButtonCell()

dgvbc.Value = strSourec[i]

dr.Cells.Add(dgvbc)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11283693.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存