且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

(WPF)启用/禁用单元格单击/行标题选择和菜单菜单项以及上下文菜单项

更新时间:2023-09-11 21:02:04

没有事件dgMainTemplate_CurrentCellChangeddgMainTemplate_SelectionChanged,但是有事件System.Windows.Forms.DataGrid.CurrentCellChangedSystem.Windows.Forms.DataGrid.SelectionChanged.您编写的名称可能只是用作或不用作这些事件的事件处理程序的方法.如果注意操作符"+ =",它会向事件的调用列表添加处理程序(很少使用的操作符也是-=).您可以看到事件对象真正发生了什么.

您可以同时使用两个事件来修改菜单项状态.唯一简单的问题是:这些事件的事件参数不携带有关选择或当前单元格的信息(两个事件都使用类型System.EventHandler).因此,在事件处理程序中,您可以键入sender参数DataGrid,并使用System.Windows.Forms.DataGrid.CurrentCell询问实例有关当前选择或单元的信息.
请参阅 http://msdn.microsoft.com/en-us/library/system .windows.forms.datagrid.aspx [ ^ ].

—SA
There are no events dgMainTemplate_CurrentCellChanged, dgMainTemplate_SelectionChanged but there are events System.Windows.Forms.DataGrid.CurrentCellChanged and System.Windows.Forms.DataGrid.SelectionChanged. The names you''ve written are probably just methods used or not used as event handlers for those events. You can see what really happens to the event objects if you pay attention to the operators "+=" which adds handlers to the event''s invocation lists (rarely used is also the operator "-=").

You can use both events to modify menu item status. The only simple problem is: event arguments for these events does not carry information on selection or current cell (both events use the type System.EventHandler). So, in the event handler, you can typecast sender parameter DataGrid and ask the instance about the current selection or cell using System.Windows.Forms.DataGrid.CurrentCell.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.datagrid.aspx[^].

—SA