PDA

Click to See Complete Forum and Search --> : How Do I Clear MSFlexGrid?


Rev. Michael L. Burns
Jun 27th, 2000, 02:59 PM
I am updating an older program that used the Grid control. I am using the MSFlexGrid that ships with VB6 to replace it since it is for the most part code compatable with the old grid and can be used as a drop in replacement for the most part. However, I have to comment out the original code below in order to get the program to work. If I do this, all the cells are loaded but some of the cells do not show the data properly (looks almost a formating problem or as if some of the cells are being padded with spaces.) It looked fine with the original grid and if viewing in Access. It looks as if the code below is supposed to clear all the cells in the Grid with exception of the top row which serves as the header with the column names.

Can anyone tell me how to imulate this?

' Clear text from the nonfixed cells
grdSermons.SelStartCol = 0
grdSermons.SelStartRow = 1
grdSermons.SelEndCol = grdSermons.Cols - 1
grdSermons.SelEndRow = grdSermons.Rows - 1
grdSermons.FillStyle = 1
grdSermons.Text = ""
grdSermons.FillStyle = 0
grdSermons.SelEndCol = 0
grdSermons.SelEndRow = 1

Also, I have two somewhat related questions. At least they have to do with the MSFlexGrid. 1) How can I sort by clicking on the header of a column and 2) Is it possible to show different background colors on the MSFlexGrid so that it would look something like greenbar paper, with odd rows white and even rows a light green.

Any help in this area would be most appreciated.

Rev. Michael L. Burns

Clunietp
Jun 28th, 2000, 01:17 PM
you'll have to manually set the alignment for each column, if its a numeric DB field, the data is right aligned, while its left aligned for text....

there is no pretty way of detecting a column header click, I would suggest a dropdown box of column names and have the user choose which one to sort by....

for the alternate row coloring, this method works, but it is VERY slow. If someone has a better way of doing it, please post it!


Dim I As Long
Dim X As Long

With MSFlexGrid1
For I = 1 To .Rows - 1 Step 2
For X = 0 To .Cols - 1
.Col = X
.Row = I
.CellBackColor = vbRed
Next X
Next I
End With

Rev. Michael L. Burns
Jun 29th, 2000, 11:26 AM
Clunietp,

Thanks ever-so-much for your sample co9de that enabled me to use alternate colors for odd and even rows in MSFlexGrid. It worked grat and the speed was not nearly as slow as I thought it would be although I'm using less than a thousand records at this time.

I like to ask a related question about the code sample. The project I am using it in has several MSFlexGrids. I'd like to use this code to provide alternate Odd-Even rows in all the grids. Is there a way to place this in a code module and can this from the grid load event of whatever the current grid is. The current code has the grid name hardcoded in the With statement. Is there a way to change this so that it works with any grid that calls this procedure?

Thanks Again,
Rev. Michael L. Burns

Clunietp
Jun 30th, 2000, 09:41 AM
Put this in a module

Public Sub FormatGrid(GridObject As MSFlexGrid, Color1 As Long, Color2 As Long)

Dim I As Long
Dim X As Long
Dim lngCounter As Long
Dim lngCurrentColor As Long
lngCounter = 0

With GridObject
For I = 1 To .Rows - 1

'alternate colors
'choose current color
If lngCounter = 0 Then
lngCurrentColor = Color1
lngCounter = 1
Else
lngCurrentColor = Color2
lngCounter = 0
End If

'color the row with the current color
For X = 0 To .Cols - 1
.Col = X
.Row = I
.CellBackColor = lngCurrentColor
Next X
Next I
End With

End Sub


and put this in your forms that have a flexgrid


Call FormatGrid(MSFlexGrid1, vbGreen, vbRed)


enjoy!

Tom

rathi
Aug 19th, 2000, 07:26 AM
Originally posted by Clunietp
Put this in a module

Public Sub FormatGrid(GridObject As MSFlexGrid, Color1 As Long, Color2 As Long)

Dim I As Long
Dim X As Long
Dim lngCounter As Long
Dim lngCurrentColor As Long
lngCounter = 0

With GridObject
For I = 1 To .Rows - 1

'alternate colors
'choose current color
If lngCounter = 0 Then
lngCurrentColor = Color1
lngCounter = 1
Else
lngCurrentColor = Color2
lngCounter = 0
End If

'color the row with the current color
For X = 0 To .Cols - 1
.Col = X
.Row = I
.CellBackColor = lngCurrentColor
Next X
Next I
End With

End Sub


and put this in your forms that have a flexgrid


Call FormatGrid(MSFlexGrid1, vbGreen, vbRed)


enjoy!

Tom

Hi Tom,

Is there any way of doing the same thing (coloring alternate rows) in Datagrid control?

If yes, pls drop a post.

Thank you.
sincerely,
Rathi

Clunietp
Aug 20th, 2000, 11:42 AM
Hi Rathi

I looked through the object model of the datagrid, and there aren't too many (it appears like there is only 1) formatting properties/methods, so it appears as though this might not be possible.

You might have to use a higher end grid control (like the Apex ones) in order to get this functionality.