in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Still can't change background color of row.

Last post 04-30-2008 11:03 AM by billg. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 04-29-2008 11:05 PM

    • billg
    • Not Ranked
    • Joined on 04-17-2008
    • Posts 4

    Still can't change background color of row.

    I am loading my data into the datasource property of the grid from a binding source during the form load.  As the rows load into the grid, I would like to test a certain column in each row being loaded and depending on the value in that column set the background color of the row to a different color ex. red, green or yellow.  This must be a simple matter because I could do it in previous versions of TrueGrid in vb 6.

     

  • 04-30-2008 1:09 AM In reply to

    Re: Still can't change background color of row.

    Hello,
     
    I would like to confirm whether you are using C1Flexgrid or C1TrueDBGrid. In case you are using
    C1Flexgrid, you may use the OwnerDrawCell Event to implement the desired behavior.
     
    1. Fist you need to set the DrawMode property of C1Flexgrid to OwnerDraw.       

    me.C1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw

    2. Now in the OwnerDrawCell event of C1FlexGrid, you may use the code something like this:

    If Me.C1FlexGrid1(e.Row, "Country") = "UK" Then

    e.Style.BackColor = Color.Red

    e.Style.ForeColor = Color.White

    ElseIf Me.C1FlexGrid1(e.Row, "Country") = "Germany" Then

    e.Style.BackColor = Color.Black

    e.Style.ForeColor = Color.White

    Else

    e.Style.BackColor = Color.Green

    e.Style.ForeColor = Color.White

    End If

    I hope this helps.

    Regards,
     
    Allen Smith
    <billg> wrote in message news:204414@10.0.1.98...

    I am loading my data into the datasource property of the grid from a binding source during the form load.  As the rows load into the grid, I would like to test a certain column in each row being loaded and depending on the value in that column set the background color of the row to a different color ex. red, green or yellow.  This must be a simple matter because I could do it in previous versions of TrueGrid in vb 6.

     



    http://helpcentral.componentone.com/cs/forums/p/75107/204414.aspx#204414

  • 04-30-2008 5:10 AM In reply to

    • billg
    • Not Ranked
    • Joined on 04-17-2008
    • Posts 4

    Re: Still can't change background color of row.

    Thank you very much your advice really helped.  I am using Flexgrid. The colors are displaying properly in the proper rows but when I click a row underneath another it takes on that color of the previous row until I move off that row.

    example.

    Row 1 = Green

    Row 2 = White

    When I click on row 2 it turns green and when I click on row 3 then row 2 turns back to white.

     

    Here is my code

    if (EventsGrid.DataSource != null && e.Row < EventsGrid.Rows.Count - 1 && e.Row != 0)

    {

    if (Int32.Parse(EventsGrid[e.Row, "RowColorID"].ToString()) == 0)

    {

    e.Style.BackColor = Color.White;

    e.Style.ForeColor = Color.Black;

    }

    else if (Int32.Parse(EventsGrid[e.Row, "RowColorID"].ToString()) == 32768)

    {

    e.Style.BackColor =
    Color.LightGreen;e.Style.ForeColor = Color.Black;

    }

    else if (Int32.Parse(EventsGrid[e.Row, "RowColorID"].ToString()) == 65535)

    {

    e.Style.BackColor = Color.Yellow;

    e.Style.ForeColor = Color.Black;

    }

    }

    }

    It's almost like it's a row behind me in the count.

  • 04-30-2008 8:28 AM In reply to

    Re: Still can't change background color of row.

    Hello,
     
    I would like to mention that indexing of the rows in the C1Flexgrid start from 1. Row 0 represents the fixed Row on
    the top. So try setting the row index accordingly. In case the issue persists, I would request you to send in your
    query to our Support team at support@componentone.com along with a sample application if possible. This will
    assist us to review the case in details and provide you with a response accordingly.
     
    I hope this will help.
     
    Regards,
     
    Allen Smith
    <billg> wrote in message news:204425@10.0.1.98...

    Thank you very much your advice really helped.  I am using Flexgrid. The colors are displaying properly in the proper rows but when I click a row underneath another it takes on that color of the previous row until I move off that row.

    example.

    Row 1 = Green

    Row 2 = White

    When I click on row 2 it turns green and when I click on row 3 then row 2 turns back to white.

     

    Here is my code

    if (EventsGrid.DataSource != null && e.Row < EventsGrid.Rows.Count - 1 && e.Row != 0)

    {

    if (Int32.Parse(EventsGrid[e.Row, "RowColorID"].ToString()) == 0)

    {

    e.Style.BackColor = Color.White;

    e.Style.ForeColor = Color.Black;

    }

    else if (Int32.Parse(EventsGrid[e.Row, "RowColorID"].ToString()) == 32768)

    {

    e.Style.BackColor =
    Color.LightGreen;e.Style.ForeColor = Color.Black;

    }

    else if (Int32.Parse(EventsGrid[e.Row, "RowColorID"].ToString()) == 65535)

    {

    e.Style.BackColor = Color.Yellow;

    e.Style.ForeColor = Color.Black;

    }

    }

    }

    It's almost like it's a row behind me in the count.



    http://helpcentral.componentone.com/cs/forums/p/75107/204425.aspx#204425

  • 04-30-2008 11:03 AM In reply to

    • billg
    • Not Ranked
    • Joined on 04-17-2008
    • Posts 4

    Re: Still can't change background color of row.

    The problem is not that it doesn't work, it works fine.  It paints all the rows correctly to start with.  Everything looks fine.

    here is a sample

    row 1 white

    row 2 white

    row 3 green

    row 4 white

    when you click on row 4 which is supposed to be white it changes to green because row 3 is green.  When you click on any other row, then row 3 changes back to white which is the correct color.  If I click on row 2 nothing changes because row 1 is white and so is row 2.  It only occurs to clicking a row that follows another row.  The newly clicked row always takes on the color of the row above it.  So the original paint is correct, it's the repainting as you click through the rows that is off.

     

Page 1 of 1 (5 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.