|
-
Nov 19th, 2007, 01:04 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Click below last row in Flexgrid
I have the following code in my FlegGrid Mouse_Down event
Code:
If y > flexFinance.CellHeight * (flexFinance.Rows + 1) Then
I use this to trap if the user has clicked below the last row, but this highlights the last row if the user clicks approx half a row below the last row.
Any ideas? Could it be to do with the width of the cell borders maybe?
If so, how do I get an accurate measurement?
-
Nov 19th, 2007, 02:27 PM
#2
Re: Click below last row in Flexgrid
.Rows is the number of rows, so you shouldn't be using the + 1
The issue is almost the cell borders - it is actually the gridlines. I can't remember right now the 'correct' method for detecting their width/height, but I think an assumption of 1 pixel is reasonably accurate.
Assuming that your scalemode is twips, you can use Screen.TwipsPerPixelY to get the height of a pixel, eg:
Code:
If y > ((flexFinance.CellHeight + Screen.TwipsPerPixelY) * flexFinance.Rows) Then
-
Nov 19th, 2007, 02:45 PM
#3
Frenzied Member
Re: Click below last row in Flexgrid
Last edited by zeezee; Nov 19th, 2007 at 02:50 PM.
-
Nov 19th, 2007, 03:40 PM
#4
Re: Click below last row in Flexgrid
Assuming all your rows are the same height use the RowHeight property instead.
If y > .RowHeight(0) * .Rows Then
-
Nov 19th, 2007, 04:38 PM
#5
Re: Click below last row in Flexgrid
 Originally Posted by zeezee
GridLineWidth
That's the one!
Note that as there is a grid line under the last row, there is no need for the separation in the calculation (which I also did first of all, but changed my mind!).
 Originally Posted by zeezee
Si, I think the no need to convert the height to twips because in mouse down the X Y is given in twips ??? But the grid width is given in Pixels which definitely needs to convert to twips , vice versa 
Oohh.. you've opened a can of worms there! I've just checked the help for the respective objects, and they are measured in:
x/y - scalemode
GridLineWidth - Pixels
CellHeight/RowHeight - Twips A nice mixture!
So, using a combination of what zeezee and brucevde posted, and allowing for scale issues, this is what I think you should use:
Code:
With flexFinance
If y > Me.ScaleY( _
(.RowHeight(0) + (.GridLineWidth * Screen.TwipsPerPixelY)) * .Rows _
, vbTwips, Me.ScaleMode) Then
..
End if
End With
(perhaps without the With and line wrapping, your choice!)
-
Nov 19th, 2007, 11:20 PM
#6
Frenzied Member
Re: Click below last row in Flexgrid
 Originally Posted by si_the_geek
A nice mixture!
Yeah. it gets better. I tried to get ScaleMode of Flex Grid. Looks like its not there. 
So your method would be great. But There is a big assumption there, The row Hieghts are equal in all cases. To make this certain you may have to set the AllowUserResizing to correct mode
Code:
MSFlexGrid1.AllowUserResizing = flexResizeColumns
or
MSFlexGrid1.AllowUserResizing = flexResizeNone
-
Nov 20th, 2007, 06:27 AM
#7
Re: Click below last row in Flexgrid
The grid doesn't have a ScaleMode, as it uses constant scales.. but unfortunately GridLineWidth uses a different scale to the rest!
You made a very good point about the row heights tho (which could be solved with a loop), but thinking about that also made me think about another issue - the rows may have been scrolled, so just using heights wouldn't be right anyway!
Thankfully in addition to the RowHeight property there is also RowPos, which says how far (with the current scrolling) that row is from the top of the grid. If we use both properties with the last row, you can be sure that row heights and scrolling are treated appropriately.
Here's a tested example, which gives a visual alert:
Code:
With flexFinance
If y >= Me.ScaleY(.RowPos(.Rows - 1) + .RowHeight(.Rows - 1), vbTwips, Me.ScaleMode) _
+ Me.ScaleY(.GridLineWidth, vbPixels, Me.ScaleMode) Then
.BackColorBkg = vbRed
Else
.BackColorBkg = vbGreen
End If
End With
I think that between the three of us we've come up with a decent solution!
-
Nov 20th, 2007, 08:12 AM
#8
Thread Starter
Frenzied Member
Re: Click below last row in Flexgrid
Wow, leave you guys to it for a day and we end up with all of this. 
When I posted the question I thought it would be a straight forward answer, such as ...
I do this or I do that
There is so much more to be thinking about!
Anyway, I have this code now:
Code:
If y > Me.ScaleY( _
(flexFinance.RowHeight(0) + (flexFinance.GridLineWidth * Screen.TwipsPerPixelY)) * flexFinance.Rows _
, vbTwips, Me.ScaleMode) Then
which is basically what si posted, but adding the FlexFinance part to it.
This works, but not exactly.
My grid only displays a maximum of 15 rows at a time.
If I display 14 rows, then if I click half way between the last row and the bottom of the grid, the last row is highlighted.
I could just add a small number of pixels onto the value for each row, but I was wondering if the size of the form would play a part?
What I mean by that is the size the user has resized the form to.
Would this work and if so, how much to add to each row?
Last edited by aikidokid; Nov 20th, 2007 at 08:34 AM.
Reason: Cpoied wrong code first of all !!!
-
Nov 20th, 2007, 09:16 AM
#9
Re: Click below last row in Flexgrid
I've re-read the help for the event, and realised I'd misread it slightly (it isn't entirely clear!).. it turns out that the Y parameter will always be twips for the FlexGrid, so the scaling doesn't need to be as complex - you just need to convert GridLineWidth to twips, eg:
Code:
If y >= flexFinance.RowPos(flexFinance.Rows - 1) + flexFinance.RowHeight(flexFinance.Rows - 1), _
= Me.ScaleY(flexFinance.GridLineWidth, vbPixels, vbTwips) Then
The size of the form is not relevant, only the size (and position) of the rows in the grid. The above takes account of the position and height of the rows, so should be accurate, no matter what the size of each row is, or where the grid is scrolled to.
Last edited by si_the_geek; Nov 20th, 2007 at 09:21 AM.
-
Nov 20th, 2007, 09:36 AM
#10
Thread Starter
Frenzied Member
Re: Click below last row in Flexgrid
Thanks again si_the_geek
Thats as accurate as I can get the cursor 
 Originally Posted by si_the_geek
I've re-read the help for the event
Is this the VB6 help or in MSDN? I would like to look at it for my own interest.
-
Nov 20th, 2007, 10:13 AM
#11
Re: [RESOLVED] Click below last row in Flexgrid
The VB6 help (aka MSDN Library).
Highlight the word mousedown in the Sub declaration, then press F1 (you should get an option of "VB" for general, or "MsFlexGridLib" for FlexGrid specific).
In this case the help isn't too specific, it just implies that X/Y are measured in the ScaleMode, which as zeezee noted earlier doesn't exist as a property - it is apparently always twips.
-
Nov 20th, 2007, 10:20 AM
#12
Thread Starter
Frenzied Member
Re: [RESOLVED] Click below last row in Flexgrid
 Originally Posted by si_the_geek
The VB6 help (aka MSDN Library).
Highlight the word mousedown in the Sub declaration, then press F1
This is why I asked as I cannot get any help files, and before anybody asks, no it's not a pirate copy 
Or at least it shouldn't be, I bought it from a programmer!
-
Nov 20th, 2007, 10:38 AM
#13
Re: [RESOLVED] Click below last row in Flexgrid
That's not too unusual unfortunately - some people ignored (or didn't take care of) the MSDN library disks, so second hand copies of VB often don't have them.
You should be able to find them on eBay for a modest price (£10 to £15), but make sure you get the October 2001 edition (or earlier, 98 onwards), as later ones don't include the VB6 help.
-
Nov 20th, 2007, 10:42 AM
#14
Thread Starter
Frenzied Member
Re: [RESOLVED] Click below last row in Flexgrid
I have the disks, from the same guy, but when I installed VB6 and it gives you the option to install MSDN, I did, but the link between the two doesn't seem to work.
If I press F1 I get the msgbox "The MSDN collection does not exist. Please reinstall MSDN"
Do you think it would be worth posting this problem in one of the other forums here? Somebody may have an answer I suppose.
-
Nov 20th, 2007, 10:44 AM
#15
Thread Starter
Frenzied Member
Re: [RESOLVED] Click below last row in Flexgrid
Just re-read your post. The MSDN collection I have is April 2004.
So this would be the problem then I guess.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|