Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2005

    Unanswered: MSFlexGrid alternate colors

    Questions pls.

    I'm using a MSFlexGrid control in my visual basic project. Now i want to have an alternate color (white & green) for my grid. I was able to do this by changing the cellbackcolor. Here's how my code looks like:

    Public Sub GridColors(ColorGrid As MSFlexGrid, R As Integer, G As Integer, B As Integer)
    For j = 0 To ColorGrid.Cols - 1
    For i = 1 To ColorGrid.Rows - 1
    If i / 2 <> Int(i / 2) Then
    ColorGrid.Col = j
    ColorGrid.Row = i
    ColorGrid.CellBackColor = RGB(R, G, B)
    End If
    Next i
    Next j
    End Sub
    The problem is, everytime i populate the grid..the changing of colors is so slow to the point that i can see that each row is being painted w/ green color. Is there any other way where I can do this?

    Thanks a lot.

  2. #2
    Join Date
    Jan 2007
    Provided Answers: 12
    I'd change the if statement to read:
    If i Mod 2 = 1 Then... 'This divides i by 2 and returns the remainder (1 or 0 in this case).
    I'll have a think about other ways we can improve this issue
    Home | Blog

  3. #3
    Join Date
    Jun 2004
    Arizona, USA
    Be sure to use a with/end with block:
    With ColorGrid
      ' Your Code, using . notation
      for I = 1 to .Rows
    End With
    And, I would use rows as the outer loop, and columns as the inner loop.

    You might also want to make the felxgrid invisible, update the colors, and make it visible again.

    Take a look at this thread (Flyguy's Flexgrid Functions) at a sister site...
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert

  4. #4
    Join Date
    Mar 2007
    Including the suggestions above, maybe you might try skipping every other row so instead of iterating through each row using:

    For i = 1 To ColorGrid.Rows - 1

    try using:

    For i = 1 To ColorGrid.Rows step 2

    If you have a lot of rows, you can cut the number of iterations in half, but even then I don't think you can save that much time.

  5. #5
    Join Date
    Oct 2005
    i did all the suggestions you posted here. but the one thing that really do the trick, is making the grid invisible before updating the colors, then making it visible again after.

    thanks to you guyz for taking the time to answer my queries.

  6. #6
    Join Date
    May 2004
    Try setting redraw property of the grid to false before the loop and True after.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts