Select a COLUMN in a datagrid?

Discussion in 'ASP .Net Datagrid Control' started by Roger Lainson, Feb 9, 2004.

  1. 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.
    Roger Lainson, Feb 9, 2004
    #1
    1. Advertising

  2. Check out:
    http://www.syncfusion.com/faq/winforms/search/893.asp

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


    "Roger Lainson" <> wrote in message
    news:...
    > 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.
    Rob Windsor [MVP], Feb 9, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hammond
    Replies:
    1
    Views:
    3,598
    bruce barker
    Nov 26, 2003
  2. Hai Nguyen
    Replies:
    0
    Views:
    385
    Hai Nguyen
    Jan 16, 2004
  3. Greg Smith
    Replies:
    0
    Views:
    525
    Greg Smith
    Apr 12, 2007
  4. Greg Smith
    Replies:
    0
    Views:
    149
    Greg Smith
    Apr 12, 2007
  5. palmiere
    Replies:
    1
    Views:
    377
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page