首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么在datagridview中加入按钮列

2012-09-27 
如何在datagridview中加入按钮列Form中有个dgView(DataGridView)请问如何在dgView中添加一个按钮列,通过按

如何在datagridview中加入按钮列
Form中有个dgView(DataGridView)
请问如何在dgView中添加一个按钮列,通过按钮列中的按钮来触发事件 


[解决办法]
直接在DataGridView的编辑列里.把需要按钮的列的ColumnType改成DataGridView就行了```
[解决办法]
生成模版列在command事件里随便加。
[解决办法]
列的columnEdit属性选择按钮,编写该按钮点击事件就可以了
[解决办法]
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
btn.name="colbtn";
btn.HeaderText= "查询明细";
btn.DefaultCellStyle.NullValue = "查询明细";
dgView.columns.add(btn);


 //占击按钮操作,也可以用EditingControlShow....
private void dGV1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dGV1.Columns[e.ColumnIndex].Name == "colbtn")
{
//占击按钮操作
}
}
[解决办法]
在datagridview的Columns属性可以加按钮列

然后触发事件是
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if((string) dataGridView1.CurrentCell.Value == "button")
{
//todo
}
}

热点排行