Select a COLUMN in a datagrid?

R

Roger Lainson

Hi,

Can anyone suggest how to select or hilight a column in a Windows
Forms datagrid, as visual feedback for an edit/copy command?

I've tried ...

private void mydatagrid_Mousedown(object sender, MouseEventArgs e)
{
// Determine location of mouse click.
DataGrid.HitTestInfo hit = mydatagrid.HitTest(e.X, e.Y);
if (hit.Type == DataGrid.HitTestType.ColumnHeader)
{
DataGridTextBoxColumn col = (DataGridTextBoxColumn)
mydatagrid.TableStyles[0].GridColumnStyles[hit.Column];
DataGridTextBox dt = (DataGridTextBox) col.TextBox;
dt.BackColor = System.Drawing.Color.Red; // just for test
}
}

.... from a snippet somewhere in the MSDN library, but this causes
cells in the hit column to have a red background only if and while
they become selected; otherwise they appear normal. Any suggestions,
or another approach altogether?

Roger.
 
R

Roger Lainson

Hi Rob,

What a great website - everything I've ever wanted to know about
datagrids and a whole lot more besides. Many thanks!

Roger.

Rob Windsor said:
Check out:
http://www.syncfusion.com/faq/winforms/search/893.asp

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada


Roger Lainson said:
Hi,

Can anyone suggest how to select or hilight a column in a Windows
Forms datagrid, as visual feedback for an edit/copy command?

...
 
J

Jeffrey Tan[MSFT]

Hi Roger,

Thanks very much for your feedback.

Yes, http://www.syncfusion.com/FAQ/WinForms/default.asp is an informative
website for WinForm FAQ.
You can find a lot of WinForm related tips from it.

I am glad you find what you want, if you have any further concern, please
feel free to post, I will help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top