Solved

component one true dbgrid v7.0

Posted on 2001-09-04
7
1,236 Views
Last Modified: 2012-06-27
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
Comment
Question by:raybetts
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6452914
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
 
LVL 1

Author Comment

by:raybetts
ID: 6453804
By picking, I mean locating, sorry for my incorrect use of english.

How does fetchcellkstyle get called?
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6455522
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:raybetts
ID: 6456437
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
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 50 total points
ID: 6456602
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
 
LVL 1

Author Comment

by:raybetts
ID: 6457089
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
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6459450
You're welcome.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question