How to get the row and column of button clicked, in the grid event handler?

Posted by younevertell on Stack Overflow See other posts from Stack Overflow or by younevertell
Published on 2010-04-29T03:39:34Z Indexed on 2010/04/29 3:47 UTC
Read the original article Hit count: 418

Filed under:
|
|

Once the added button in grid is clicked, how to find which row and column the button is located in the grid event handler, like click event or some other events? Not the button click event handler

        #region Grid event handler setup
        myGrid.MouseEnter += new MouseEventHandler(myGrid_MouseEnter);
        myGrid.MouseLeave += new MouseEventHandler(myGrid_MouseLeave);
        myGrid.MouseDown += new MouseButtonEventHandler(myGrid_MouseDown);
        myGrid.MouseUp += new MouseButtonEventHandler(myGrid_MouseUp);
        #endregion

Thanks

I notice that Boyan has some solution for the button click event handler case

http://stackoverflow.com/questions/363100/in-wpf-how-can-i-determine-what-column-row-in-a-grid-a-control-is

In the Click event handler for the button you say:

int row; Button btn = sender as Button; if (btn != null) { row = Grid.GetRow(btn); // And you have the row number... } else { // A nasty error occurred... }

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf