我正在使用vb.net windows application.i有一个网格视图..我正在填充我的数据网格视图:
在load事件中我写了这样的代码:
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
所以我的网格视图如下:
我想在我的图片栏中添加按钮。所以我尝试这样的代码:但是这又添加了一列。
Dim btn As New DataGridViewButtonColumn
gv.Columns.Insert(6, btn).
所以如何在我的图片栏中添加按钮
答案 0 :(得分:3)
您需要将按钮名称设置为此类似的工作:
Dim btn As New DataGridViewButtonColumn
btn.HeaderText = "Click Data"
btn.Text = "Click Here"
btn.Name = "btn"
btn.UseColumnTextForButtonValue = True
gv.Columns.Insert(6, btn)
答案 1 :(得分:0)
尝试以下代码以显示DataGridView:
Dim btn As New DataGridViewButtonColumn()
DataGridView1.Columns.Add(btn)
btn.HeaderText = "Click Data"
btn.Text = "Click Here"
btn.Name = "btn"
btn.UseColumnTextForButtonValue = True