在 vb.net 中的数据网格视图的特定列中添加按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21155365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
adding button in particular column of data-grid view in vb.net
提问by user3106114
i am working on vb.net windows application.i have a grid view ..i am populating my data grid view like this:
我正在使用 vb.net windows application.i 有一个网格视图..我正在填充我的数据网格视图,如下所示:
in load event i wrote code like this:
在加载事件中,我写了这样的代码:
Dim cd As SqlCommandBuilder = New SqlCommandBuilder(adapter)
adapter = New SqlDataAdapter("select c.cid,c.CompanyName,d.dtId,d.dtName as Department,d.dtPhone as Phone,d.dtEmail as Email,d.empimage as Image from CompanyMaster_tbl c join DepartmentMaster_tbl d on c.Cid=d.cId order by cid", con.connect)
dt1 = New DataTable
bSource = New BindingSource
adapter.Fill(dt1) 'Filling dt with the information from the DB
bSource.DataSource = dt1
gv.DataSource = bSource
gv.Columns("cid").Visible = False
gv.Columns("dtId").Visible = False
so my grid view like this:
所以我的网格视图是这样的:
i want to add button in my image column..so i try code like this: but that is adding one more column.
我想在我的图像列中添加按钮..所以我尝试这样的代码:但那是再添加一列。
Dim btn As New DataGridViewButtonColumn
gv.Columns.Insert(6, btn).
so how i can add button in my image column
那么我如何在我的图像列中添加按钮
回答by Al-3sli
You need to set the button name to this to work like so :
您需要将按钮名称设置为这样才能工作:
Dim btn As New DataGridViewButtonColumn
btn.HeaderText = "Click Data"
btn.Text = "Click Here"
btn.Name = "btn"
btn.UseColumnTextForButtonValue = True
gv.Columns.Insert(6, btn)

