Handle the DataGrid's MouseUp event, and within the hander call the DataGrid.Select method.
using System.Drawing;
using System.Windows.Forms;
private DataGrid dataGrid1;
// ...
dataGrid1.MouseUp += new MouseEventHandler( dataGrid1_MouseUp );
// ...
private void dataGrid1_MouseUp( object sender, MouseEventArgs e )
{
Point point = new Point( e.X, e.Y );
DataGrid.HitTestInfo hti = dataGrid1.HitTest( point );
if ( hti.Type == DataGrid.HitTestType.Cell )
{
dataGrid1.CurrentCell = new DataGridCell( hti.Row, hti.Column );
dataGrid1.Select( hti.Row );
}
}
Contributed from George Shepherd's Windows Forms FAQ