我有List
GridView
,我想在每个CellEndEdit
添加相同的GridView
个事件。
可以确定哪个gridview触发CellEndEdit
事件?
lst.Add(new RadGridView());
RadGridView radgridview= lst.Last();
radgridview.CellEndEdit += new GridViewCellEventHandler(radgridview_CellEndEdit);
private void radgridview_CellEndEdit(object sender, GridViewCellEventArgs e)
{
//I want to know here which radgridview is modified
}
答案 0 :(得分:3)
标准事件模式将事件源作为sender
参数中的参数传递。因此,您只需将sender
转换为RadGridView
并拥有相关的实例:
private void radgridview_CellEndEdit(object sender, GridViewCellEventArgs e)
{
RadGridView sendingGridView = sender as RadGridView;
if (sendingGridView == null || !lst.Contains(sendingGridView))
return; // just to be sure
}
显然,在这种情况下,sender
是GridViewEditManager
,因此您可能会得到RadGridView
这样的内容:
private void radgridview_CellEndEdit(object sender, GridViewCellEventArgs e)
{
GridViewEditManager manager = sender as GridViewEditManager;
RadGridView sendingGridView = manager?.GridViewElement?.GridControl;
if (sendingGridView == null || !lst.Contains(sendingGridView))
return; // just to be sure
}