怎样才可以右击选中datagridview控件中的单元格(1000分问题) 我想实现像大部分音乐播放器的播放列表中右击弹出
菜单的
功能,如播放,
删除等 但datagridview和list
Box 控件都
不支持右击选项中啊,怎么办啊 __________________________________________________________________________
添加右键
菜单 __________________________________________________________________________ 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) __________________________________________________________________________ 了解一下`` __________________________________________________________________________ 学习了 __________________________________________________________________________