同じコンテキスト メニューを使用する複数のリストビューがあるため、コンテキスト メニューを生成したコントロールを取得しようとしています。
以前にこれを行ったことがありますが、コンテキストメニューに埋め込まれたコンボボックスを使用しているため、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
私は何を間違っていますか?