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!

Synchronization of 2 grids - horizontal scrolling makes 2nd grid out of sync

Status
Not open for further replies.

KALP1

Programmer
Aug 26, 2016
102
0
0
IN
I have 2 grids. They are attached together 1 below other. As I horizontally scroll upper grid and focus is on the last column -> upper grid scrolls/slips while lower grid remains as it is. Secondly when I resize any column in upper grid lower grid columns are not resized.

How to tackle these sync. issues. I have created 2 separate grid classes and in upper grid's events I have written code to sync. bottom grid.
Is there any other way to do that.
 
Is there any other way to do that.

Other than what? You say you have written some code. So how can we offer you any other code without knowing what you have already done?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I don't want to give impression that upper and lower grid are 2 different grids. As soon as cursor is at last column and enter is pressed upper grid slips. So, is there any better way to make 2 grid behave as 1 single unit,so that resizing columns of 1 also resizes columns of other grid.
 
One way might perhaps be within the "resize" event of grd1.

Code:
myform.grd2.height=this.height
myform.grd2.width=this.width

Utmost blessings!
 
I want columns of grid2 to resize as column of grid1 resizes.
 
I want columns of grid2 to resize as column of grid1 resizes.

Then write code in the Resize event of the columns of Grid1. Let the code change the Width property of the corresponding column in Grid2 to match that of Grid1.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You may also bind lots of events from one to the other grid, but still would need additional code handling the syncing, I guess. Eg binding one Resize to another grids Resize won't do anything, but you could have one codebase and have the same Resize code in both grids only concerned with their own resize. Same for Columns, etc.

In the end it could be easier in the current situation to program both grids to also modify their sibling grid.

What are you trying to establish overall? Seems your using two grids above each other to get a horizontal Partioninig/Panels.

Bye, Olaf.
 
I have placed 1 grid of 1 record at the top and data grid below it. In grid1 user could write in various columns and based on that data "and/or" operation is used to create a filtered condition for the bottom grid (say for ex. if user writes 'A' in name column and 'U' in country column,then all records with name beginning with 'A' and country beginning with 'C' will be filtered in grid2). I am giving users impression that they have 1 entity in which they are typing and filtering is done simultaneously on the below grid.I have 1 another grid - grid3 at the bottom in which totals are shown. As data is filtered , totals are updated too. So these 3 grids make my 1 component for displaying data as well as filtering.

Grid2 and Grid3 have 0 header height.So as user resizes header of grid1, grid2 and grid3 should be resized.
Now, when user resizes top grid bottom grid remains as it is. Secondly,grid's slipping is more annoying as when user presses tab/enter at last column upper grid slips while bottom 2 remains as it is. In 1 grid, Allowcellselection is .T. and rest 2 have Allowcellselection is .F.
 
I've done this by using normal controls above a grid. I see the interface idea, but this is just burdening oneself with too much things to look out for, in the first place no grid is unscrollable, even if just by arrow keys. You have many problems you don't have with simple text boxes.

Bye, Olaf.
 
Actually , I also tried to place textboxes over grid headers, but as grid loses focus , textboxes go behind the grid although its Z-Order property is set to .T.. I have then searched a lot to know reason behind this. In book "1001 things to know about visual foxpro", there was written, this is problem and in each form control's it has to be written in Gotfocus event to set textboxes control zorder and visible. This was cumbersome job and was form specific and approach was not generalized,So I opted to go for 2 grids.

Olaf,did u mean the same thing as I described for textboxes or any thing else.
 
Given that the upper grid has only one row, my immediate thought would be: why use a grid? Why not a set of textboxes? It's true that you probably wouldn't be able to resize the textboxes in sync with the grids columns, but is that so important?

Then you say:

I also tried to place textboxes over grid headers, but as grid loses focus , textboxes go behind the grid although its Z-Order property is set to .T..

The answer to that is to place the texboxes above the grid (that is, higher up the form), rather than on top of it.

In short, I am suggesting that you forget about making it look as if the whole thing is just a single grid. It might not look as slick, but is it really worth the effort?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
No, not above in z-order, on top.

The grid is always drawn for each line, it only is a graphical representation except the current record, but it rigorously draws over anything. So no, I'm not talking about overlayed controls. Much simpler on top of the grid headers, outside the grid.

Bye, Olaf.
 
Ok, then in this scenario, when grid scrolls horizontally, will the above textboxes also scroll i.e will I be required to add new textboxes hiding previous one.
 
then in this scenario, when grid scrolls horizontally, will the above textboxes also scroll i.e will I be required to add new textboxes hiding previous one.

I'm not sure why you would want to do that. Using your example, you would have a texbox for Name, and one for Country. Why would you want to add or hide textboxes?

Or are you saying that you want to create a completely generic interface which can be used with arbitrary tables? That you don't know in advance what columns you would need or how wide they will be?

Perhaps you could clarify that point before we go much futher.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
First: Why would it need to be a textbox for each column? You typically only have only some columns of interest for filtering, for example. Your generic idea is what I wouldn't implement.

Obviously textboxes outside of a grid are not part of the grid, how could you expect them to be in sync with the grid? Of course you would need to code this. But it's possible using a concept of a scrollable container. (eg see Mikes article on scrollable container: You can keep this scrollable programmatically only, when not displaying scrollbars and then do the syncing via grid events (eg see scrolled and afterrowcolchanged, calling a syncgridfilter method orienting on objtoclient positions)

You'd be much more in control of this, opposed to the difficulty of letting a grid not scroll with arrow keys.

And even without the concept of a form on a form you could work with a simple container as clipping element and move textboxes via their left position.

Bye, Olaf.

PS: Besides all this, visit universalthread.com and look into their Downloads section. Search for grid and you'll find some classes for incremental search gridd and others.
 
Yes Mike , I want to make a generic interface which could be used anywhere I call it with arbitrary tables. If all of columns don't fit on the grid ,then only hidding and adding new textboxes comes in picture.

Olaf, I have read scrollable container. As far as my forms are concerned, I have modal forms, so I don't think it will work in my case.
 
Well, then don't use a scrollable form embedded, but a normal container. It's more work to set all controls Left property instead of only viewport left, but it's doable, and you have full control.

Besides that, the limitation is only about the manual usage of scrollbars and you a) won't want visible scrollbars in that embedded form and b) can still scroll it programmatically. So that limitation doesn't hinder you using that.

Bye, Olaf.
 
OK, so we accept that you want to create a generic device with an arbitrary number of columns, and therefore an arbitrary number of selection criteria. That in itself is not difficult. What's giving us problems is the fact that you want the selection criteria boxes to always appear above the corresponding grid columns, even when the user horizontally scrolls the grid or resizes the columns (or, presumably, when they re-arrange the order of the columns, assuming you allow that).

If you could relax that requirement, the whole thing would be considerably easier.

The way I would do it is to use textboxes for the selection criteria, but to arrange them in a vertical block, one beneath the other, to the right of the grid. I would create a class that contains the grid, with a blank space for where the textboxes will appear. At its simplest, the Init event of the class would look at the number of columns in the grid (or, perhaps, the number of fields in the underlying cursor), and instantiate that number of textboxes, one beneath the other.

In fact, I'd go one step further. I would not assume that every field in the cursor would be eligible as a selection criterion. I would identify the key fields that the user is likely to want to select on, and provide a property of the class that tells it which those fields are. It would be up to the developer to specify a value for that property at design time.

It would also be up to the developer to ensure that, when placing the class on the form, there is enough space to show the required number of textboxes.

I know this won't look quite as slick as the original plan - that is, making it look like the user is entering the criteria directly into the grid - but it would be considerably easier to implement.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top