Wednesday, September 11, 2013

Grid Dynamics' Power!!!

What is Dynamic?

Adjective
(of a process or system) Characterized by constant change, activity, or progress.
Noun
A force that stimulates change or progress within a system or process.

So Dynamic can change.  It is the opposite of being Static or Fixed.


In VFP Grid, there is only one real row and the rest are just mirrors of the first one manipulated by VFP to show different values. It means that conditions on objects (textbox, combobox, checkbox, etc) on a column are static.  What condition and formatting you applied to an object of a cell applies to the rest of the cells belonging to that column.

But since there definitely is a need for us to reflect on a cell certain values based on several conditions, then that is where Dynamic Properties of a grid is needed (see VFP help on available Dynamic Properties).  A very powerful feature of grid that makes me prefer it over to listbox.


Yesterday inside Foxite, I finally understood the need of a fellow member with the sample he provided which is allowing a combobox inside a column to change values or sort of being filtered based on a combination of values of two fields (or column1 and Column5).  And I showed him how to attain that by employing DynamicCurrentControl Property of the grid.

What is DynamicCurrentControl?

Please just refer to my early posting in Weblogs about this: http://weblogs.foxite.com/sandstorm36/2008/08/09/placing-various-images-on-a-grid/



I will presume you went to weblogs link above and read it and is now more familiar with DynamicCurrentControl.

If utilizing DynamicCurrentControl has solved the OP's problem inside Foxite, what is this post for?

It is better you read this as well to understand better what this post is for: http://www.foxite.com/archives/comboboxdropdown-list-in-grid-0000385150.htm

Okay, I again will presume that you read the above link so we will proceed now.  You see, what I showed him is to utilize two comboboxes, each containing a list of its own and later perform switching to show a certain combobox based on conditions on the values of Column1 and Column5 of the grid.

The problem is, that approach is based on the sample form.  The reality of his need is to have, based on what I have shown, more than that 2 comboboxes.  Per initial review by the OP on his real need, it may be around 29 comboboxes for that column.  Heck!  Even though DynamicCurrentControl can give me that ability of filtering, I cannot even think of myself creating those many comboboxes and seeding each of those with its own lists.  No Sir!

So I muled over his problem some more because I know with VFP, nothing is impossible!!!.

DynamicCurrentControl another approach!

After a long circuitous approach pointing to several links (sorry for that, those are needed for you to understand the advantage of this next approach better), we are finally coming to the real point of this post.  The purpose of this is to show another way of utilizing DynamicCurrentControl property of the grid without using 29 or more objects on a column but instead just one! Am I kidding?  Nope!

Here is the trick.  We still need to use two objects on that column. First is the default Textbox object and the other is "a" combobox.  The combobox will then get re-queried based on a condition on the "active row".  Combobox will appear only on active row; while the rest of the rows will be displayed using the default textbox object.  This ensures that whatever we later do on RowSource of the combobox will not affect inactive cells; as values of those is no longer dependent on the combobox and is simply handled by textbox.

The problem with the first approach using and showing combobox on all cells of the column to reflect its current values can be solved only by creating several comboboxes; each having its own sets of values based on several conditions (sort of filtering). Because if not and we use only a single combobox, other values no longer on the active combobox will disappear on other cells of that column.

That approach of using multiple comboboxes is acceptable and I may use it myself if there is no alternative. But there is which is to allow the combobox to handle values of that cell "only on active row". Because when you do that, that default textbox object can take care of all the values of those inactive cells and whatever you do on that combobox won't affect the rest. Coding is easier and grid is lighter.

Here is a sample form for that (I utilized the sample form OP has given us in Foxite to show this approach so I won't have to create a new one).  Extract and run it and later dig inside the form for codes so you can see more clearly what has to be done.  https://dl.dropboxusercontent.com/u/15025358/dynamic.rar


This approach is the same approach I used here:  http://sandstorm36.blogspot.com.au/2013/05/activex-dtpicker-mscomctl2dtpicker2-on.html

Cheers!

No comments:

Post a Comment