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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent Grid scrolling

Status
Not open for further replies.

Gerrit Broekhuis

Programmer
Aug 16, 2004
313
1
18
NL
Hi,

If we have a grid with more than enough space to show all records, is there a way to prevent the grid from scrolling?

Regards, Gerrit
 
ScrollBars = 0. Well, it doesn't not exactly prevent scrolling. If the user uses arrow keys to navigate in the grid cells, that also scrolls it, but if, as you say, the data fits into the grid, even that's not possible to cause grid scrolling.

Otherwise the BeforeRowColChange event will allow you to disallow changes that go beyond visible rows and columns, so that could be used to actively prevent this mechanism of the grid, and once you achieve that, you could introduce other controls for scrolling, like buttons. As I indicated in a thread of Mandy_crw recnetly, that control is nice to have, too, for a userinterface on a tablet where you could also use touch on scrollbars, but where those can become pretty thin, too thin for good control with fingers. And then using buttons and the doscroll method can be a better touch interface, for example.

Chriss
 
Hi Chriss,

I’m well aware of the scrollbars. Nevertheless the scrollwheel remains active and I intend to prevent this from happening. I don’t want scroll buttons, as we can enable the scrollbar(s) when needed.

I don’t understand yet what you mean with the BeforeRowColChange event. Do you perghaps have an example how this could disable scrolling?

Regards, Gerrit
 
Look into the help. A nodefault in BeforRowColChange means it doesn't allow changing row/column.

In a simple case, disallowing any change by just programming nodefault:
Code:
oForm = CreateObject("noscrollgridform")
oForm.Show()
Read events

DEFINE CLASS noscrollgridform AS form
	Height = 250
	Width = 384

	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 2, ;
		Height = 108, ;
		Left = 12, ;
		RecordSource = "SampleData", ;
		RecordSourceType = 1, ;
		ScrollBars = 0, ;
		Top = 12, ;
		Width = 209, ;
		Name = "Grid1"
		
	ADD OBJECT grid2 AS grid WITH ;
		ColumnCount = 2, ;
		Height = 59, ;
		Left = 228, ;
		RecordSource = "SampleData2", ;
		RecordSourceType = 1, ;
		ScrollBars = 0, ;
		Top = 12, ;
		Width = 144, ;
		Name = "Grid2"

	PROCEDURE Load
		Create Cursor Sampledata (field1 c(10), field2 c(10))
		Insert into Sampledata values ('A','B')
		Insert into Sampledata values ('C','D')
		Insert into Sampledata values ('E','F')
		locate

		Create Cursor Sampledata2 (field1 c(10), field2 c(10))
		Append From Dbf("Sampledata")
		Locate
	ENDPROC

	PROCEDURE grid2.BeforeRowColChange
		LPARAMETERS nColIndex
		Nodefault
	EndProc
	
	Procedure QueryUnload()
	   Clear Events 
	EndProc 

ENDDEFINE

Gerrit Broekhuis said:
the scrollwheel remains active

You're right, both grids still scroll when the have a) focus and b) the mouse poiner hovers over the cells and you use the scrollwheel.

Well, you could disable the grids, so they can't get focus at all, then that's also no problem.

Chriss
 
...Also, nodefault in the Mousewheel event of the grid prevents scrolling by mousewheel without disabling the whole grid. That can be used, if you still want to allow the user to activate cells, select the data and use copy&paste.

Chriss
 
Gerrit,

Do you by any chance have a copy of 1001 Things You Wanted to Know About Visual Foxpro?

If so, it has some code which (I think) exactly solves your problem. It is on page 174. Unfortunately, it's too long for me to type into this thread (and I wouldn't want to infringe the authors' copyright), but if you can get hold of a copy, it would be worth a look.

But that's assuming I have correctly understood your question. I am assuming that, when you scroll the grid down to the bottom of the table, you see several rows of white space below the last row. You want to fix it so that the last record in the cursor sits on the last physical row in the grid, with no empty rows below.

Apologies if I have misunderstood the problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

I think I have already solved my problem, but since I have this book I will take a look later this week.

Regards, Gerrit
 
Mike,

interesting reference, thanks.

I don't think it fits the description:

Gerrit Broekhuis said:
a grid with more than enough space to show all records
That compares to the first grid in my sample code where the grid has more rows and columns than the recordsource.

But to me, this raises the question of how the books' code handles that situation. As it has no chance to put the last record at the bottom grid row, because there are less records than rows, I think it would just stick and fulfill Gerrits requirement anyway.

But to me nodefault in grid.mousewheel on top of nodefault in grid.BeforeRowColchange solves the problem for Gerrit's case. I just wait for hi confirmation, but I'm sure that it works I just added it to my example, easy enough, and mousewheel scrolling also is suppressed.

At first, I only thought about scrolling by either the scrollbars - therefore remove them - and also thought by scrolling through moving in the records with the arrow keys, therefore the nodefault in BeforeRowColchange. I overlooked scrolling by mouse wheel, but that is fixed and can be made airtight with nodefault in the grid.mousewheel event. That's fixing the grid where it is. Not only for the case the rows fully fit but also if you simply want to fix the grid to the portion of data it shows.

The bonus about the 1001 Things code would be to allow scrolling in a way you'd expect it to stop when the bottom record is in the bottom grid row, whereas VFP continues until the bottom record is in the top grid row. But Gerrit's case is simply that there are fewer records than grid rows and maybe even fewer columns than the grid area could show horizontally.

In my sample, I also showcased a different scenario where the records are not fitting the grid to verify and show that the scrolling also is hindered for that extra case, where scrolling would of course still be reasonable, but nodefault in BeforeRowColchange can really hinder scrolling, not only the change of the focus to another cell, that was the reason I included it in the demo form. Simply try it out. It doesn't cover mousewheel scrolling, but nodefault in that event does and then it's a complete solution to make a non-scrollable grid.

No doubt a resonable scrolling mode, as I would call this, is better usable in the general case and would also work in Gerrits special case of less data than visible cells, too. On the other hand there is no need four counteracting too far scrolling when you don't allow it to begin with.

Chriss
 
My solution, once more, in short:

Solution 1: Have
1. nodefault in the grid.BeforeRowColchange() event
2. nodefault in the grid.MouseWheel() event
3. scrollbars=0

That fixes the grid where it is, the only point is that a click into a cell is not activating it as BeforeRowColchange prevents the focus from getting into the clicked cell, even if grid.enabled=.t.
But if you want this to use the grid for displaying some data that fully fits the grid area and should not be moved in any way, this can do it, or...

...even simpler Solution 2:
1. Set grid.enabled=.f.
2. scrollbars=0

So mainly disabling a grid, disables its scrolling, too, no matter how a user tries to scroll it anyway.

The second solution also works with Scrollbars>0, but you will just show unusable scrollbars, which are, of course, unnecessary.

Chriss
 
Hi Chris,

OK, I have a lot to choose from. I will continue working on this later this week.

Thanks!

Regards, Gerrit
 
How about disabling the grid?



If you want to get the best response to a question, please check out FAQ184-2483 first.
 
That book is available on line at


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
That book is available on line

I wonder if that's legal? Have the copyright holders given Google permission to post the entire book on line? After all, Hentzenwerke are still selling the book.

MIke



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Good question, but there it is, searchable even

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
No, to the best of my knowledge, no Hentzenwerke copyright holders have given Google rights.

As you know, those of us with rights in the Hacker's Guide open-sourced the book a couple of years ago and put it in a repository, so other folks could update.

Tamar
 
Well, if you look at it in detail, Google Books is not publishing the whole book. Google Books shows book previews only. But in this case, the book preview is most pages except a few, when you scroll through you sometimes come across a message like this, omitting pages.

preview_gkffb0.jpg


I don't know which right they claim and on which basis they choose their preview extract, but if you ask me they don't just exhaust what they can show as a preview. This can't be called preview anymore.

Chriss
 
Hi,

I’ve limited my scrolling by calculating the record’s grid position and the grid’s capacity (there may be more records or less records that can fit in the sizable grid).

Regards, Gerrit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top