Who fired the RadGridView ValueChanged

2 Answers 32 Views
GridView
Carl
Top achievements
Rank 1
Iron
Iron
Iron
Carl asked on 06 Mar 2024, 05:06 PM

I have a series of grids on a form, and all but the first one is created at runtime. Each grid has the same ValueChanged event handler attached to it. How can I tell which grid fired it?

private void ValueChanged(object sender, EventArgs e)
{

}

I tried intercepting the CellClick event (since that fires first) and getting the id from the tag property into a form-wide variable but that seems like a major kludge.

private async void CellClick(object sender, GridViewCellEventArgs e)
{
     myTag = (int)((MasterGridViewTemplate)e.Column.OwnerTemplate).Owner.Tag;
}

Any better ideas?

Thanks

Carl

Carl
Top achievements
Rank 1
Iron
Iron
Iron
commented on 07 Mar 2024, 01:39 PM

I'm afraid your approach didn't work. When I tried it both ActiveEditor properties were null. No matter, the approach I showed in my original post did work. However, maybe as a future enhancement the sender parameter should always have a reference to the control

Thanks

Carl

2 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 07 Mar 2024, 12:31 PM

Hello Carl,

What comes up to my mind is to check the ActiveEditor property of the RadGridViews. Basically, when a cell is in edit mode, the ActiveEditor property of the control will hold a reference to this editor. This property is null when the RadGridView is not in edit mode. In the ValueChanged event handler, you can check each RadGridView ActiveEditor property if it is Null or not.

private void RadGridView1_ValueChanged(object sender, EventArgs e)
{
    var gridEditor1 = this.radGridView1.ActiveEditor;
    var gridEditor2 = this.radGridView2.ActiveEditor;

    if (gridEditor1 != null)
    {

    }

    if (gridEditor2 != null)
    {

    }
}

You can share if this approach will work for you.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
0
Dinko | Tech Support Engineer
Telerik team
answered on 08 Mar 2024, 02:22 PM

Hi Carl,

It is strange that the ActiveEditor property is null in your application. Maybe I am missing something here. Can you share how the cells in the controls are edited? 

If I go back to the ValueChanged event, the sender in my case will be the currently active editor. From the editor you could get its parent GridViewElement.

private void RadGridView1_ValueChanged(object sender, EventArgs e)
{
    var editor = sender as BaseGridEditor;
    if (editor != null)
    {
        var gridElement = (editor.EditorManager as GridViewEditManager).GridViewElement;
    }

    var gridEditor1 = this.radGridView1.ActiveEditor;
    var gridEditor2 = this.radGridView2.ActiveEditor;

    if (gridEditor1 != null)
    {

    }

    if (gridEditor2 != null)
    {

    }
}

Can you give this approach a try and share if it works for you?

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Carl
Top achievements
Rank 1
Iron
Iron
Iron
commented on 08 Mar 2024, 02:44 PM | edited

I'm binding a BindingList collection to the grid's DataSource. The only editable column is a checkbox bound to a bool property.

Your approach does work better. Using the gridElement variable I can now do this:

int selectedGridTag = (int)gridElement.GridControl.Tag;

Thanks

Carl

Tags
GridView
Asked by
Carl
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or