简体   繁体   中英

Which gridview of a list fires an event

I have a List of GridView and I want to add the same CellEndEdit event at each GridView .

it is possible to determine which gridview fire the CellEndEdit event ?

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
}

The standard event pattern passes the source of the event as argument in the sender parameter. So you can simply cast sender to RadGridView and have the relevant instance:

private void radgridview_CellEndEdit(object sender, GridViewCellEventArgs e)
{
    RadGridView sendingGridView = sender as RadGridView;
    if (sendingGridView == null || !lst.Contains(sendingGridView))
        return; // just to be sure
}

Obviously in this case the sender is a GridViewEditManager , so you may get your RadGridView like this:

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM