列表的哪个gridview触发事件

时间:2016-06-17 12:18:59

标签: c# gridview

我有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
}

1 个答案:

答案 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
}

显然,在这种情况下,senderGridViewEditManager,因此您可能会得到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
}