.NET DataGrid: Selecting the whole row when clicked on a cell
This is something I was trying for sometime and the only way I managed to do it earlier was by disabling the datagrid. The other solutions proposed were by sub-classing the datagrid control and by overriding the default behaviour. But I found a better and easy way described in this blog.
I am posting the code snippet here, just for my future reference as well as for anyone else’s benefit.
1. To handle mouse click events. When the user selects a cell by clicking on it.
private void dg_MouseUp( object sender, System.Windows.Forms.MouseEventArgs e )
2. The solution for getting the row to select when the user navigates using the arrow keys.
private void dg_CurrentCellChanged( object sender, System.EventArgs e )
I tried this on a .NETCF Pocket PC app and it worked great. Also, it solved one of the issues that I had to solve, easily.