Attention: We are retiring the ASP.NET Community Blogs. Learn more >

WinForms DataGrid row highlighting

Here's something that I've burnt hours on before... HOW TO: set the row color in WinForms datagrid when selected?

Carson McComas posted this piece of code on the WinForms list this morning:

[--1--]
The solution for getting the mouse click to select the whole row:

private void dg_MouseUp( object sender, System.Windows.Forms.MouseEventArgs e )
{
 dg.Select(dg.CurrentRowIndex);
}

[--2--]
The solution for getting the row to select when someone navigates the DG
with the arrow keys

private void dg_CurrentCellChanged( object sender, System.EventArgs e )
{
 dg.Select(dg.CurrentRowIndex);
}


That thread also supplied this nice link to a forum post that describes the TaskVision implementation...

http://www.windowsforms.com/Forums/ShowPost.aspx?tabIndex=1&tabId=41&PostID=3374

Here's a link to join the WinForms list:

http://www.aspalliance.com/lists/SignUp/list.aspx?l=62&c=16

No Comments