读书人

datagridview 平添按钮列 除了DataGri

发布时间: 2012-12-23 11:28:15 作者: rapoo

datagridview 添加按钮列 除了DataGridViewButtonColumn,还有别的方法吗
datagridview 添加按钮列 除了DataGridViewButtonColumn,还有别的方法吗
[解决办法]
还可以在属性面板那里加 添加列,把列属性设为按钮列
[解决办法]
拖一个Button到窗体上,Visible 为False
如下处理事件,则当鼠标点击到第三列中时,当前行显示Button

 Private Sub DataGridView1_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
Me.DataGridView1.Controls.Clear()
if DataGridView1.CurrentCellAddress.X = 2 then '第三列中显示Button
Button1.Visible = True '设置控件允许显示
Button1.Enabled = True
Button1.Width = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Height '获取单元格高并设置为btn的宽
Button1.Height = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Height '获取单元格高并设置为btn的高
Me.DataGridView1.Controls.Add(Button1)
Button1.Location = New System.Drawing.Point(((Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Right) - (Button1.Width)), Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Y) '设置btn显示位置
end if
end sub

[解决办法]
唉,都不能满足需要了

读书人网 >VB Dotnet

热点推荐