Results 1 to 4 of 4

Thread: Datagrid row colors

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    8

    Unhappy Datagrid row colors

    Has anyone know a way to place colors on individual rows on a datagrid? I have managed to use DataGrid1.SelBookmarks.Add DataGrid1.RowBookmark(i) to highlight an area or row but this is not exactly what I want.

    Any ideas?

    Pierre

  2. #2
    Lively Member jalopez's Avatar
    Join Date
    Jul 2001
    Location
    Puerto Rico
    Posts
    108

    Thumbs up Color!!!

    I think that Sheridan Data Widgets (third party controls) will do something for you.

    This may be not what you are looking for, but it gives you the chance to change color for even and odd rows in a data grid. These controls also have a set of very nice properties that simplifies many common and not so common tasks.

    I was trying to do the same with the conventional data grids that come with VB but it is impossible. It is possible that someone out there could have a hidden trick but I don't think so.

  3. #3
    Fanatic Member RSINGH's Avatar
    Join Date
    May 2001
    Location
    London
    Posts
    522
    You can do it with teh msflexgrid. But you have to paint teh individual cells that make up the row. It also gets painfully slow when you have a large number of rows.

    To loop through the grid use something like

    Code:
    Private Sub ColorCells(color)
    Dim j As Integer
    'This sub runs through all the cells setting the backcolor of them
        
        For j = 0 To grdTasks.Cols - 1
            grdTasks.Col = j
            grdTasks.CellBackColor = color
        Next
    End Sub
    The liver is bad. It must be punished.

  4. #4
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    MS flexgrid colouring can be made much faster using the redraw property and the fillstyle. Here are some examples of a 0 to 5 column flexgrid
    VB Code:
    1. 'This section just fills the grid
    2. Private Sub Command1_Click()
    3.     With MSFlexGrid1
    4.         .Redraw = False 'Halts redraws until complete
    5.         .Rows = 0
    6.         For x = 0 To 999
    7.             .AddItem x & vbTab & x & vbTab & x & vbTab & x & vbTab & x & vbTab & x
    8.         Next
    9.         .Redraw = True
    10.     End With
    11. End Sub

    This section colours each item by row. If you are doing specific things to specific rows then this will be appropriate
    VB Code:
    1. Private Sub Command2_Click()
    2.     With MSFlexGrid1
    3.         .Redraw = False
    4.         .FillStyle = flexFillRepeat 'Set fill style
    5.         For x = 0 To 999
    6.             .Row = x
    7.             .Col = 0 'Used with fill style for first col
    8.             .ColSel = 5 'used with fill style for last col
    9.             .CellBackColor = vbRed 'Colours whole row 0 to 5
    10.         Next
    11.         .Redraw = True
    12.     End With
    13. End Sub

    If you only want to colour a specific column and u have many rows it is much faster to colour by column.
    VB Code:
    1. Private Sub Command3_Click()
    2.     With MSFlexGrid1
    3.         .Redraw = False
    4.         .FillStyle = flexFillRepeat
    5.         For x = 0 To 5
    6.             .Col = x
    7.             .Row = 0
    8.             .RowSel = 999
    9.             .CellBackColor = vbRed
    10.         Next
    11.         .Redraw = True
    12.     End With
    13. End Sub
    Both methods are acceptably fast if redraw is set to false and true as appropriate
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

Posting Permissions

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



Click Here to Expand Forum to Full Width