Solved

component one true dbgrid v7.0

Posted on 2001-09-04
7
1,246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

737 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