我在WPF中使用WindowsFormHost创建了一个datagridview,代码为XAML:
<WindowsFormsHost Margin="154,63,786,544">
<wf:DataGridView
x:Name="DGV"
Location="0, 0"
ColumnHeadersVisible="True"
SelectionMode="FullRowSelect"
MultiSelect="False"
SelectionChanged="DataGridViewOnSelectionChanged"
/>
</WindowsFormsHost>
以及ContextMenuStrip,代码XAML:
<Window.Resources>
<ContextMenu x:Key="CMS">
<MenuItem Header="CMS">
<MenuItem Header="1" Click="one">
</MenuItem>
<MenuItem Header="2" Click="two">
</MenuItem>
<MenuItem Header="3" Click="three">
</MenuItem>
<MenuItem Header="4" Click="four">
</MenuItem>
</MenuItem>
</ContextMenu>
</Window.Resources>
我想在datagridview上“右键单击”时显示ContextMenuStrip所以我写了这个:
Public Sub ClickMouse(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick
If e.Button = Windows.Forms.MouseButtons.Right Then
CMS.Show(Windows.Forms.DataGridView.MousePosition)
MsgBox("WTF")
End If
End Sub
但是当我右键单击DataGridView“DGV”时,ContextMenuStrip“CMS”没有出现?我做错了什么?
非常感谢提前。