上下文菜单显示下次单击时的更改



我正在使用DevExpress TreeList。我有两种方法MouseDown()MouseUP()通过右键单击从树列表中获取项目,然后在运行时显示一个上下文菜单/弹出菜单并对其进行更改。

问题:上下文菜单或弹出菜单在下次单击时显示barSubItem3.Enabled = false;更改。不在当前点击上。

private void TreeList1_MouseDown(object sender, MouseEventArgs e)
{
TreeList tree = sender as TreeList;
if (e.Button == MouseButtons.Right && ModifierKeys == Keys.None
&& tree.State == TreeListState.Regular)
{
Point pt = tree.PointToClient(MousePosition);
TreeListHitInfo info = tree.CalcHitInfo(pt);
if (info.HitInfoType == HitInfoType.Cell)
{
SavedFocused = new TreeListNode();
SavedFocused = tree.FocusedNode;
tree.FocusedNode = info.Node;
/* get value from node that is clicked by column index */
switch (SavedFocused.GetValue(0).ToString())
{
case "A":
barSubItem3.Enabled = false;
break;
case "B":
barSubItem3.Enabled = true;
break;
}
}
}
}
private void TreeList1_MouseUp1(object sender, MouseEventArgs e)
{
TreeList tree = sender as TreeList;
if (e.Button == MouseButtons.Right && ModifierKeys == Keys.None
&& tree.State == TreeListState.Regular)
{
popUpMenu.ShowPopup(MousePosition);
}
}  

我想这是因为您实际上正在修改项目的状态,一旦它已经显示。

请改用 PopupMenuT显示地图 事件。下面是有关如何使用 GridView 修改PopUpMenu的示例。

private void Whatever_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
{
var menu = e.Menu;
var hi = e.HitInfo;
if (!(sender is GridView view)) 
return;
var inDetails = (hi.HitTest == GridHitTest.EmptyRow);
if (menu == null && inDetails)
{
menu = new DevExpress.XtraGrid.Menu.GridViewMenu(view);
e.Menu = menu;
}
if (menu == null) 
return;
//If there are any entries, show "Duplicate" button
var rowHandle = hi.RowHandle;
if (!view.IsDataRow(rowHandle)) return;
var mnuDuplicate = new DXMenuItem("Duplicate",
async delegate { await ClickDuplicate(); },
Properties.Resources.copy_16x16)
{
BeginGroup = true
};
menu.Items.Add(mnuDuplicate);
}

相关内容

  • 没有找到相关文章

最新更新