DataGrid LoadingRow事件未触发 [英] DataGrid LoadingRow event not firing
问题描述
我正在尝试在datagrid行中捕获鼠标左键单击,但是LoadingRow事件从不触发.但是,UnloadingRow事件确实会触发,因此我不确定我缺少什么.
I am trying to capture a left mouse click in a datagrid row, but the LoadingRow event never fires. However, the UnloadingRow event does fire, so I am not sure what I am missing.
private DataGrid _gdShortNoticeOrders;
partial void ShortNotice_Created()
{
this.FindControl("gdShortNoticeOrders").ControlAvailable += new EventHandler<ControlAvailableEventArgs>(gdShortNoticeOrders_ControlAvailable);
}
private void gdShortNoticeOrders_ControlAvailable(object sender, ControlAvailableEventArgs e)
{
_gdShortNoticeOrders = e.Control as DataGrid;
if (_gdShortNoticeOrders == null)
return;
_gdShortNoticeOrders.LoadingRow += _gdShortNoticeOrders_LoadingRow;
_gdShortNoticeOrders.UnloadingRow += _gdShortNoticeOrders_UnloadingRow;
}
private void _gdShortNoticeOrders_LoadingRow(object sender, DataGridRowEventArgs e)
{
// This never executes!
e.Row.MouseLeftButtonUp += new MouseButtonEventHandler(_gdShortNoticeOrdersRow_MouseLeftButtonUp);
}
private void _gdShortNoticeOrders_UnloadingRow(object sender, DataGridRowEventArgs e)
{
// This fires when screen is closed.
e.Row.MouseLeftButtonUp -= new MouseButtonEventHandler(_gdShortNoticeOrdersRow_MouseLeftButtonUp);
}
private void _gdShortNoticeOrdersRow_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
// Custom code here...but it never runs because the LoadingRow event never fires
}
推荐答案
我遇到了同样的问题.以我为例,这种情况发生在从SQL Server视图加载数据的DataGrid上. (我的意思是,与其关联的实体是SQL Server中的一个视图.)
I am having the same problem. This happens, in my case, on a DataGrid that loads data from a SQL Server view. (I mean, the entity associated with it is a view in SQL Server).
当数据网格正在从表的集合中加载数据时,事件将正确触发.
The events fire correctly when the datagrid is loading data from a collection of a table.
现在,我想找出我可以使用的其他事件,因为我找不到任何有用的东西.
Now I'd like to find out which other event I may use, as I cannot find any useful.
乔瓦尼
这篇关于DataGrid LoadingRow事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!