Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB5 MSFlexgrid re-display from row 0

Status
Not open for further replies.

peterd51

Technical User
Feb 22, 2005
109
GB
Hi,

background:
I'm using a flexgrid in VB5 to diplay names and data in multiple columns. Some of the figures have dollars, pounds (sterling) or euro symbols so a straight 'sort' doesn't work correctly.

It works Ok if I copy the 'sort' column to another hidden grid with a second column holding an index vlaue. I can recalculate the value of each sum into sterling and then after sorting refresh the main grid using the index to get it into the right order.

In the main grid I can't use a fixed row 0 for the title, sort-selection, etc, as I want the user to be able to select an item from the grid to display additional info on that item, and if row 0 is fixed then as a user clicks on row 0 to sort on a specific column it returns row 1.

I've got a row of labels above each column and the user will click on a label to sort on that column. The label hold the column title which doesn't get moved with the vertical scroll bar, ie, similar to a fixed row 0.

The up/down arrows showing the sort direction get placed in row 0 and the 'data' goes in row 1 and down from there.

This is all doing what I want it to and although I may have missed some obvious or easier method of doing the same thing I'm happy to leave it as it is, although I'd still like to hear any ides on the subject.


The current problem:
When I scroll down the flex grid a bit and click on a label to sort on a different column it does the sort and changes the display but the grid stays where it is. What I want it to do is to display the grid from row 0 after the sort.

I've tried setting .row 0 and .setfocus, .top. .toprow none of these work as I get an error on them.

Any ideas please?

Regards
Peter
 
Hi,

well, I found that I can set .rows to 1 and then back to the original value and it works OK.

It takes care of UK pounds, USD, Euro and will even distinguish between US and Euro cents by checking other columns, as required, to list pretty close to the actual value.

I already had a browser set up to check on-line to get up-to-date currency info at the start of each day.

I'd still like to know if there's a 'correct' way to reset the grid display to start at row 0 though!

Regards
Peter
 

I don't know why your .TopRow did not work, but it works for me.

On the Form there is just MSFlexGrid1 and Command1:
Code:
Option Explicit
Dim i As Integer

Private Sub Form_Load()

For i = 1 To 100
    MSFlexGrid1.AddItem "Item Number " & i
Next i

End Sub

Private Sub Command1_Click()
    MSFlexGrid1.TopRow = 1
End Sub

Have fun.

---- Andy
 
Hi,

ah, yes, I may have missed off the '=1' as I thought it was a setting that just specified 'the top row'. Thanks for the clarification.

The help-file doesn't show an example and the second CD that was mentioned some weeks ago just seems to contain links to the internet so it's not much use unless I'm on-line.

Thanks
Peter
 

I hope you have checked the "Require Variable Declaration" checkbox in your VB IDE (Tools - Options - Editor Tab - Code Settings frame). This puts [tt]Option Explicit[/tt] at the top of your code.

When you had '= 1' missing, the 'Start With Full Compile' would show you the problem right away.

Have fun.

---- Andy
 
Hi,

thanks for the suggestion but I leave that unchecked as I always add 'option explicit' myself.

I can see now that 'start with full compile' is a 'run' option but I've never heard of it before.

Thanks
Peter


 
>I leave that unchecked as I always add 'option explicit' myself.


As a matter of interest, given you always add it why would you not check that option and save yourself some typing and avoid any chance of forgetting?
 
A Suggestion ...

When you load your grid ... can you add another column that holds a value = money column equal to Strling Value of the money column... this column can have a width of zero and thus be invisible to user


Then when click on Money column redirect the sort to be done on extra column

Peter Wallace
 
Hi strongm

'As a matter of interest, given you always add it why would you not check that option and save yourself some typing and avoid any chance of forgetting?'

sometimes I'm playing around with something quick and dirty to see if an idea works and I don't want to declare variables then. When I say I always add it, that really only applies to something more than a few lines long.

Plus I don't like giving /any/ MS product too much control over my PC. It's a personal choice as I found out many years ago that things that run automatically cause me problems. For instance I never have any kind of predictive text or auto correct turned on in word, etc. I make mistakes and I correct them in my own time. It's a hobby so time isn't that important to me.

PeterWallace:

'can you add another column that holds a value = money column equal to Strling Value of the money column'

I considered that but I'd have to do the calculations anyway before adding the figure to the hidden column. As a separate sub-routine I can use it for currency calculations in other parts of the program too.

It only takes 60mS to transfer to a hidden grid, with recalc as required, sort it, and transfer back picking up the data from the array.

To show the same column in reverse order takes 20mS as I don't do the initial copy and sort, just redisplay in reverse order.

A direct sort in the original grid might only take a few milliseconds but the users only see the screen blink in the time it takes for my method to complete.

I'm interested in the correct way to do things without being a fanatic about it. If it looks easy then I'll do it the VB way, otherwise I'll stick with Quick Basic as I know how to do what I want with that.

Regards
Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top