[VB.NET]怎样才可以右击选中datagridview控件中的单元格(1000分问题)

VB.NET源码-156个实用实例哦…… <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
怎样才可以右击选中datagridview控件中的单元格(1000分问题)
我想实现像大部分音乐播放器的播放列表中右击弹出菜单的功能,如播放,删除等
但datagridview和listbox 控件都不支持右击选项中啊,怎么办啊
__________________________________________________________________________
添加右键菜单
__________________________________________________________________________
datagridview 是支持的右键的

相应的datagridview 的 ContextMenuStrip属性加入ContextMenuStrip控件~~~

QQ:512000940 联系~~~
__________________________________________________________________________
1.添加ContextMenuStrip(cxmOperationMenu)控件
2.DataGridView(grdMusicList)绑定cxmOperationMenu (在grdMusicList的ContextMenuStrip属性中选择cxmOperationMenu来绑定)
3.双击grdMusicList的CellMouseDown事件并添加代码
private void grdMusicList_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button != MouseButtons.Right || e.RowIndex < 0)
{
cxmOperationMenu.Enabled = false;
return;
}
else
{
this.grdMusicList.ClearSelection();
this.grdMusicList.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
cxmOperationMenu.Enabled = true;
}
}
__________________________________________________________________________
用这个就可以~~


VB.NET code

Private Sub DataGridView1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDown
DataGridView1.ClearSelection() 如果需要响应ctrl键的多选则用if判断是否按下ctrl来限定这句
If e.Button = Windows.Forms.MouseButtons.Right Then
DataGridView1(e.ColumnIndex, e.RowIndex).Selected = True
End If
End Sub
__________________________________________________________________________
随便哪个cellMouse****点击事件都可以(DOWN,CLICK,UP)
__________________________________________________________________________
了解一下``
__________________________________________________________________________
学习了
__________________________________________________________________________
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值