Solved

component one true dbgrid v7.0

Posted on 2001-09-04
7
1,205 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:raybetts
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You're welcome.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now