How to get the row and column of button clicked, in the grid event handler?
- by younevertell
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...
}