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
Printable View
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
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.
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
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:
'This section just fills the grid Private Sub Command1_Click() With MSFlexGrid1 .Redraw = False 'Halts redraws until complete .Rows = 0 For x = 0 To 999 .AddItem x & vbTab & x & vbTab & x & vbTab & x & vbTab & x & vbTab & x Next .Redraw = True End With 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:
Private Sub Command2_Click() With MSFlexGrid1 .Redraw = False .FillStyle = flexFillRepeat 'Set fill style For x = 0 To 999 .Row = x .Col = 0 'Used with fill style for first col .ColSel = 5 'used with fill style for last col .CellBackColor = vbRed 'Colours whole row 0 to 5 Next .Redraw = True End With End Sub
If you only want to colour a specific column and u have many rows it is much faster to colour by column.
Both methods are acceptably fast if redraw is set to false and true as appropriateVB Code:
Private Sub Command3_Click() With MSFlexGrid1 .Redraw = False .FillStyle = flexFillRepeat For x = 0 To 5 .Col = x .Row = 0 .RowSel = 999 .CellBackColor = vbRed Next .Redraw = True End With End Sub
Regards
Stuart