2014-01-16 55 views
0

我在application.i有一個網格視圖..我正在填充我的數據網格視圖這樣vb.net窗口工作:添加按鈕,在數據網格視圖的特定列在vb.net

負載

事件我寫這樣的代碼:

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 

所以我的網格視圖像這樣:enter image description here

我想在我的圖像添加按鈕column..so我嘗試這樣的代碼:但就是再增加一個柱。

Dim btn As New DataGridViewButtonColumn 
     gv.Columns.Insert(6, btn). 

所以,我怎麼能在我的圖像列中添加按鈕

回答

2

您需要的按鈕名稱設置爲這個像這樣的工作:

Dim btn As New DataGridViewButtonColumn 
btn.HeaderText = "Click Data" 
btn.Text = "Click Here" 
btn.Name = "btn" 
btn.UseColumnTextForButtonValue = True 
gv.Columns.Insert(6, btn) 
+0

這次加入新column..sir我不想添加新列 – user3106114

+0

我想要獲取圖像列中的按鈕 – user3106114

+0

您不能在普通列上插入按鈕類型單元格,它必須是按鈕列。 –