This is a migrated thread and some comments may be shown as answers.

CellClick in child table of RadGridView

7 Answers 176 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bernd Mueller
Top achievements
Rank 1
Bernd Mueller asked on 21 Jul 2010, 12:38 PM
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

7 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 22 Jul 2010, 08:46 AM
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
0
Bernd Mueller
Top achievements
Rank 1
answered on 22 Jul 2010, 10:43 AM
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
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 22 Jul 2010, 12:12 PM
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
0
Bernd Mueller
Top achievements
Rank 1
answered on 22 Jul 2010, 12:29 PM
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
0
Emanuel Varga
Top achievements
Rank 1
answered on 22 Jul 2010, 12:32 PM
Hello Bernd,

You're welcome, glad to help
0
Emanuel Varga
Top achievements
Rank 1
answered on 22 Jul 2010, 05:12 PM
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
0
Bernd Mueller
Top achievements
Rank 1
answered on 22 Jul 2010, 05:23 PM
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!
Tags
GridView
Asked by
Bernd Mueller
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Bernd Mueller
Top achievements
Rank 1
Share this question
or