Change font color for certain rows in DataGridview

Discussion in 'Microsoft Dot NET Framework Forms' started by Elmo Watson, Aug 3, 2007.

  1. Elmo Watson

    Elmo Watson Guest

    In ASP.Net, using a Gridview, you can conditionally set the forecolor of
    each row (or column), based on certain criteria using the RowDataBound event

    But I can't find an event that is similar in WinForms

    I need to set the forecolor to red, if the the entry type (in column 1) is a
    1 - -

    How would I do this in a DataGridView?
     
    Elmo Watson, Aug 3, 2007
    #1
    1. Advertisements

  2. Elmo Watson

    Elmo Watson Guest

    Also forgot to mention - the column I'm using for the condition is invisible



    "Elmo Watson" <> wrote in message
    news:...
    > In ASP.Net, using a Gridview, you can conditionally set the forecolor of
    > each row (or column), based on certain criteria using the RowDataBound
    > event
    >
    > But I can't find an event that is similar in WinForms
    >
    > I need to set the forecolor to red, if the the entry type (in column 1) is
    > a 1 - -
    >
    > How would I do this in a DataGridView?
    >
     
    Elmo Watson, Aug 3, 2007
    #2
    1. Advertisements

  3. Elmo Watson

    ClayB Guest

    You can try using th eCellFormatting event.

    void dataGridView1_CellFormatting(object sender,
    DataGridViewCellFormattingEventArgs e)
    {
    object val = dataGridView1["Col1", e.RowIndex].Value;
    if (e.RowIndex > -1 && e.ColumnIndex >= -1
    && val != null && val.Equals(2))
    {
    e.CellStyle.BackColor = Color.Red;
    }
    }

    ====================
    Clay Burch
    Syncfusion, Inc.
     
    ClayB, Aug 4, 2007
    #3
  4. Elmo Watson

    nikhil soni Guest

    Re: You can try using th eCellFormatting event.

    Thank you very much.it really help me to solve my Issue

    Nikhil Soni

    > On Friday, August 03, 2007 4:34 PM Elmo Watson wrote:


    > In ASP.Net, using a Gridview, you can conditionally set the forecolor of
    > each row (or column), based on certain criteria using the RowDataBound event
    >
    > But I can't find an event that is similar in WinForms
    >
    > I need to set the forecolor to red, if the the entry type (in column 1) is a
    > 1 - -
    >
    > How would I do this in a DataGridView?



    >> On Friday, August 03, 2007 5:10 PM Elmo Watson wrote:


    >> Also forgot to mention - the column I am using for the condition is invisible



    >>> On Friday, August 03, 2007 8:46 PM ClayB wrote:


    >>> You can try using th eCellFormatting event.
    >>>
    >>> void dataGridView1_CellFormatting(object sender,
    >>> DataGridViewCellFormattingEventArgs e)
    >>> {
    >>> object val = dataGridView1["Col1", e.RowIndex].Value;
    >>> if (e.RowIndex > -1 && e.ColumnIndex >= -1
    >>> && val != null && val.Equals(2))
    >>> {
    >>> e.CellStyle.BackColor = Color.Red;
    >>> }
    >>> }
    >>>
    >>> ====================
    >>> Clay Burch
    >>> Syncfusion, Inc.



    >>> Submitted via EggHeadCafe
    >>> Custom task processes in SharePoint Designer Workflows
    >>> http://www.eggheadcafe.com/tutorial...ocesses-in-sharepoint-designer-workflows.aspx
     
    nikhil soni, Nov 25, 2010
    #4
    1. Advertisements

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. Replies:
    0
    Views:
    1,003
  2. Tony B

    DataGridView change row color

    Tony B, Apr 19, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    830
    Tony B
    Apr 19, 2006
  3. Guest

    Select a row of a DataGridView control with a certain column value

    Guest, Aug 11, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    298
    Guest
    Aug 11, 2006
  4. Steve K

    DataGridView - Change selection color when focus lost

    Steve K, Dec 30, 2008, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    2,025
    Steve K
    Dec 30, 2008
  5. enrico

    DataGridView with rows in plus rows

    enrico, Feb 20, 2009, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    386
    Jibesh
    Feb 27, 2009
Loading...

Share This Page