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.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top