我正在尝试获取生成上下文菜单的控件,因为将有多个列表视图使用相同的上下文菜单。
我以前做过,但现在我在上下文菜单中使用嵌入式组合框似乎变得复杂了 1000 倍:
当我在组合框中选择一个项目时,我需要确定哪个列表视图产生了菜单:
private void tsCboAddCharList_SelectedIndexChanged(object sender, EventArgs e) {
if (tsCboAddCharList.SelectedItem == null) return;
ContextMenuStrip theTSOwner;
if (sender.GetType().Name.Contains("ToolStripComboBox")) {
ToolStripComboBox theControl = sender as ToolStripComboBox;
ToolStripDropDownMenu theMenu = theControl.Owner as ToolStripDropDownMenu;
ContextMenuStrip theTlStrip = theMenu.OwnerItem.Owner as ContextMenuStrip;
ContextMenuStrip theCtxStrip = theTlStrip as ContextMenuStrip;
theTSOwner = theCtxStrip;
} else {
theTSOwner = (ContextMenuStrip)((ToolStripItem)sender).Owner;
}
ListView callingListV = (ListView)theTSOwner.SourceControl; //always null
我究竟做错了什么?