<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)
__________________________________________________________________________
了解一下``
__________________________________________________________________________
学习了
__________________________________________________________________________
怎样才可以右击选中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)
__________________________________________________________________________
了解一下``
__________________________________________________________________________
学习了
__________________________________________________________________________