更新时间:2023-09-11 21:02:04
没有事件dgMainTemplate_CurrentCellChanged
,dgMainTemplate_SelectionChanged
,但是有事件System.Windows.Forms.DataGrid.CurrentCellChanged
和System.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 eventsdgMainTemplate_CurrentCellChanged
,dgMainTemplate_SelectionChanged
but there are eventsSystem.Windows.Forms.DataGrid.CurrentCellChanged
andSystem.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 typeSystem.EventHandler
). So, in the event handler, you can typecastsender
parameterDataGrid
and ask the instance about the current selection or cell usingSystem.Windows.Forms.DataGrid.CurrentCell
.
See http://msdn.microsoft.com/en-us/library/system.windows.forms.datagrid.aspx[^].—SA