VDF-GUIdance logo



  Visual DataFlex Logo
  

Shared knowledge leads to accumulated knowledge

        Printer Friendly Page


Rearrange dbGrid Columns

by Dalton Pulsipher

Summary

Recently at MMISL I showed a subclass that enabled rearranging of columns in a dbGrid.
You can now use this feature yourself! You will just need the .pkg and .dll file attached. Basic instructions are in the class and can also be found at the read more link below.
Size: 8 KB Download
Date Created: 15/11/2004
Date Updated: 02/02/2005
Author: Dalton Pulsipher
Company: HCSS


This mixin class can be added to your local dbGrid subclass to enable rearranging of columns in your grid.

Here is a rundown of the basic concept to get it working and a discussion of some of the implementation issues that you might encounter.

How it works


Before creating your dbGrid, the subclass creates a set of arrays to hold the grid information.
Included in the creation of these arrays is the reverse map and original map arrays. They hold your maps back to where the columns stood originally before any rearranging was done.

When the dbgrid is displayed it pulls an encoded version of the reverse map array from the registry and "reloads" it and the original map array with this information. It then maps the grid to it's state where you left it last using the map.

Some side items for functionality:
The expression strings you register are saved in an array and evaluated at runtime for each record in entry_display. Our drag and drop interface was created by Frank Cheng and requires Rearrange.dll.
If you don't want to depend on the dll, you will need to augment mouse_down and mouse_up (or anything that serves the purpose) in order to call Move_Column from the grid with meaningful parameters.

Implementation


  1. Wrap this subclass around your existing dbGrid class.
  2. For each expression column do two things
    1. Take the string you would have passed in the entry_item command and send it to Register_Expression_Column . For example, if you used to have Entry_Item (fFunc(self,giTemp)+Employee.PayRate) for column 0 you would now Send Register_Expression_Column 0 "(fFunc(self,giTemp)+Employee.PayRate)" in the object's open code
    2. Replace that line Entry_Item (fFunc(self,giTemp)+Employee.PayRate) with an Entry_Item to a database field. This keeps dataflex from putting the expression column settings on an unwanted column in an unpredictable fashion. I recommend just using File.recnum for each expression column to be consistent. The file and field you use is immaterial as it will be overwritten when the program starts up. (Note that you can dynamically override any column from its original contents by sending Register_Expression_Column with a new expression because of this functionality)
  3. Notice that the nature of this subclass is in selecting some properties, moving them, and augmenting them to mimic a desired behavior. You will need to make calls to the reverse map arrays when dealing with grid properties as needed. The arrays are kept up to date and are mainly for this purpose. A good example is Column_Option. Here is how you would set the Column_Option for what was originally item 5:
    • Set Column_Option Item (Integer_Value(aReverse_MapArray(self),5)) to (NOENTER) FALSE
You basically need to go through your code and replace X with (Integer_Value(aReverse_MapArray(self),X)) in your property calls.
  1. If you add fields to the grid in a later release, the map will be ignored the first time back and will revert your grid to it's original state. After the application is closed the first time a new reverse map string is stored with the correct number of columns indicated and the mappings will again be remembered.

Usability Tips


  • To protect 5 columns on the left from being rearranged, Set Protect_From_Rearrange to 4
  • To keep the rearranged columns during this session from being saved, Set pbReMapSupported to FALSE
  • To stop all rearranging immediately, Send Toggle_Rearrange_Enabled FALSE
  • To query if rearranging is enabled, Get IsRearrangeEnabled to bEnabled
  • If Item 2 was originally the Quan field, Item (Integer_Value(aReverse_MapArray(self),2)) now holds Quan
  • If you need info on Item 2, it was originally Item (Integer_Value(aOriginal_MapArray(self),2))

Download



RearrangeMixin-1-0-0.zip ~8kb This is the control itself

RearrangeMixinDemo.zip ~56kb This is a little demo workspace with the 1.0 version of the control included. The demo has been created using VDF10.1. Just double-click the .ws file in order to be able to test-run the example view.