CellClick in child table of RadGridView

8 posts, 1 answers
  1. Bernd Mueller
    Bernd Mueller avatar
    38 posts
    Member since:
    May 2010

    Posted 21 Jul 2010 Link to this post

    Hello,

    is there an easy way to distinguish within the CellClick event of the RadGridView if it is in the main table or in a child table?

    Thank you for your help!

    Bernd
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 22 Jul 2010 Link to this post

    Hello Bernd,

    You could try checking the sender, check if that equals to the main grid, if not than it's the child, if you need anything more specific please elaborate more.

    Emanuel
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bernd Mueller
    Bernd Mueller avatar
    38 posts
    Member since:
    May 2010

    Posted 22 Jul 2010 Link to this post

    Hello Emanuel,

    thanks for the idea, but the sender in the CellClick event is a cell and not the grid. Even with the Parent property of this cell i am not able to find if this cell belongs to the main grid or a child table of that grid.

    The whole problem is that i want to do something special if someone clicks a special cell in the main grid, but the event is also raised for the child tables. Or is there an option to disable event raising in these child tables?

    Best regards

    Bernd
  5. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 22 Jul 2010 Link to this post

    Hello again,

    Sorry about the previous answer i was always using the GridViewCellEventArgs to get the selected cell so i was assuming that the sender was the grid.

    I can offer you a "working solution" but it's not very profesional, i got it to work by doing this:

            private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
            {
                var gridCellElement = (GridDataCellElement)sender;
                if (this.radGridView1.Rows.Contains(gridCellElement.RowInfo))
                {
                      .... do something
                }
            }

    I hope this helps
  6. Bernd Mueller
    Bernd Mueller avatar
    38 posts
    Member since:
    May 2010

    Posted 22 Jul 2010 Link to this post

    Hello Emanuel,

    thank you very much. That really works! Now i can easily detect if the click was inside the main table or in a child table.

    Best regards

    Bernd
  7. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 22 Jul 2010 Link to this post

    Hello Bernd,

    You're welcome, glad to help
  8. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 22 Jul 2010 Link to this post

    Hello again,

    I forgot to tell you not to forget to test if RowIndex != -1, mainly

    Snippet
            private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
            {
                if (e.RowIndex == -1)
                {
                    return;
                }
                
                var gridCellElement = (GridDataCellElement)sender;

                if (this.radGridView1.Rows.Contains(gridCellElement.RowInfo))
                {
                    //Do Something
                }
            }

    or if typeof sender is not GridDataCellElement return
  9. Bernd Mueller
    Bernd Mueller avatar
    38 posts
    Member since:
    May 2010

    Posted 22 Jul 2010 Link to this post

    Hi,

    thank you for your concern. I also check the ColumnIndex. This event is also fired for some clicks on the grid that have a negative ColumnIndex, but a positive RowIndex and vice versa.

    Long story short: It works perfectly now.

    Thanks again!
Back to Top
UI for WinForms is Visual Studio 2017 Ready