• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1304
  • Last Modified:

component one true dbgrid v7.0

Say I have a column of figures, how do I go about picking say the worst or best figure in that column and changing its colour.  I know how to change the colours, I need to know how to find the cell and determine whether the cell is the best one or the worst one.

cheers,

ray.

ps. I am using the oledb version
0
raybetts
Asked:
raybetts
  • 4
  • 3
1 Solution
 
Valliappan ANSenior Tech ConsultantCommented:
What do you mean by best one or worst one? Ok, you would need to do this, from the FetchCellStyle Event. Something like this:

Private Sub TDBGrid1_FetchCellStyle(ByVal Condition As Integer, ByVal Split As Integer, Bookmark As Variant, ByVal Col As Integer, ByVal CellStyle As TrueOleDBGrid70.StyleDisp)

If TDBGrid1.Columns(0).CellText(Bookmark) = 0 Then
    CellStyle.ForeColor = vbBlue
ElseIf TDBGrid1.Columns(0).CellText(Bookmark) > 200 Then
    CellStyle.ForeColor = vbRed
End If

End Sub

0
 
raybettsAuthor Commented:
By picking, I mean locating, sorry for my incorrect use of english.

How does fetchcellkstyle get called?
0
 
Valliappan ANSenior Tech ConsultantCommented:
The event occurs when the grid is to refresh cell data, for a column(s), for which, the FetchStyle property is set to True.




0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
raybettsAuthor Commented:
valli_an

I now understand how the methods and events work, but how do I scan a particular column and work out the highest or lowest fig

eg

loop till column(x) = end 'loop a given column
   
   'find worst fig and change colour
   if row.figure = lowest then row.forecolour = red

obviously the syntax above is incorrect, but hopefully it gives you an idea of what I want to do.


0
 
Valliappan ANSenior Tech ConsultantCommented:
How are you displaying the data to grid. Is it using a bound or unbound method.

You should be able to find it using the underlying data, say, recordset or Xarraydb or whatever.

Otherwise, loop through the columns collection like this:

Dim mMaxRow As Long, mMaxVal, mMinVal, mCurVal
if Col = 0 Then 'or whatever column
  mMaxRow = rs.RecordCount
  mMaxVal = 0
  mCurVal = 0

  TDBGrid1.Row = 0
  mMinVal = TDBGrid1.Columns(0).Value

  For j = 0 To mMaxRow - 1
   TDBGrid1.Row = j
   mCurVal = TDBGrid1.Columns(0).Value
   'your code to get max. and min. values
   if mCurVal > mMaxVal Then
       mMaxVal = mCurVal
       'change style here.
   elseif mCurVal < mMinVal Then
       mMinVal = mCurVal            
   End If
  Next                    
End If

Or, if you could do in table, using query it could be better, and faster. This would be very slow, since every time it fetches a cell, it will go through this code.
0
 
raybettsAuthor Commented:
the slowness of looping was the thing I was worried about and I was hoping the grid would have had a neat trick to combat this!  Still cant complain, could still be using the std vb grid!!!!

Thanks for the help.
0
 
Valliappan ANSenior Tech ConsultantCommented:
You're welcome.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now