| VB Extension Tools HTML project report | |
| Project: CodeHelperCollection | Module: CGridEditor |
| Module Type  | Class module  |
|---|---|
| File  | C:\Code\EE-projects\units\vb\standard\src\GridEditor.cls  |
| Author  | Ralf Kunsmann  |
| Date  | 2000 11 14  |
| Purpose  |
Extends 'MSHFlexGrid' control to be used to edit values. Each cell that is out of the FixedRows, FixedCols - range can be edited if cell BackColor property is set to 'vbWindowBackground' or to 'vbWhite'.  |
| Implementation  |
We use a TextBox control, react an DoubleClick and KeyDown events. The TextBox is placed in front of the current cell and data is copied from cell to TextBox when editing is started - reverse when editing is finished.  |
| Usage  |
Call the 'Create' - method after instancing the object variable of type 'CGridEditor'. Call the 'Destroy'-method in 'Form_Unload' - event of the form you are using the class with. Declare the object variable 'WithEvents' to receive the 'DataChange' - events, which tells You, that user edited data.  |
| Procedure 'Create' | List of procedures |
| Scope/Type  | Public Function  |
|---|---|
| Code parameters  |
frmA As Form grdA As MSHFlexGrid Optional NumericOnly As Boolean = False Optional NumericFormat As String = "0.00" Optional SelectionItems As Collection Optional Column As Long Optional ThousendSeparatorForbidden As Boolean = True  |
| Code return value  | Boolean  |
| Author  | Ralf Kunsmann  |
| Date  | 2001 05 03  |
| Purpose  | Prepare the class instance to be able to work.  |
| Result  | True on success, else False  |
| In parameters  |
Reference to a TextBox control, required from to class to be able to work. The grid control, with which to class has to work Optional Boolean: Defining that only numerical input values are allowed Optional String: Defining the numerical value formating relevant only if 'numerical input only' is set. Optional Collection: Strings, the user can choose from. Optional Long: If Class Object is user to only edit one certain column - number of the column  |
| Procedure 'Destroy' | List of procedures |
| Scope/Type  | Public Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2001 05 03  |
| Purpose  | Destroy object references to the TextBox and Grid control.  |
| Procedure 'CurrentlyEditing' | List of procedures |
| Scope/Type  | Public Property (Get)  |
|---|---|
| Code return value  | Boolean  |
| Author  | Ralf Kunsmann  |
| Date  | 2003 04 07  |
| Purpose  |
Find out and return, if we are currently editing a grid cell. This is the case if either TextBox or ListBox is visible.  |
| Result  | Boolean: True is currently editing, else False.  |
| Procedure 'Class_Initialize' | List of procedures |
| Scope/Type  | Private Sub  |
|---|
| Procedure 'frm_Paint' | List of procedures |
| Scope/Type  | Private Sub  |
|---|
| Procedure 'grd_GotFocus' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 21  |
| Purpose  |
If grid gets focus while editing is in process (lst or txt are visible) set focus back to edit control.  |
| Procedure 'grd_KeyDown' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  |
KeyCode As Integer Shift As Integer  |
| Author  | Ralf Kunsmann  |
| Date  | 2001 05 03  |
| Purpose  | Start edit mode, if the user presses return or F2 key.  |
| In parameters  | Default VB event parameters.  |
| Procedure 'grd_MouseDown' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  |
Button As Integer Shift As Integer X As Single Y As Single  |
| Author  | Ralf Kunsmann  |
| Date  | 2001 05 03  |
| Purpose  | Start edit mode, if user clicks the grid.  |
| In parameters  | Default VB event parameters.  |
| Procedure 'grd_Scroll' | List of procedures |
| Scope/Type  | Private Sub  |
|---|
| Procedure 'lst_KeyDown' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  |
KeyCode As Integer Shift As Integer  |
| Author  | Ralf Kunsmann  |
| Date  | 2001 06 29  |
| Purpose  |
If the user presses Tab or Return key, we do navigation purpose in the grid. Additionally we call 'SetEditMode' after navigating.  |
| In parameters  | Default VB event parameters.  |
| Procedure 'lst_KeyPress' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  | KeyAscii As Integer  |
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 21  |
| Purpose  |
Suppress any key inputs to the ComboBox (that is the way we imitate the ComboBox Style 'vbComboDrop', which we can set at run time).  |
| In parameters  | VB defaults  |
| Procedure 'lst_LostFocus' | List of procedures |
| Scope/Type  | Private Sub  |
|---|
| Procedure 'txt_GotFocus' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Code Helper  |
| Date  | 25.02.2003  |
| Purpose  | Select the hole text in the TextBox control.  |
| Procedure 'txt_KeyDown' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  |
KeyCode As Integer Shift As Integer  |
| Author  | Ralf Kunsmann  |
| Date  | 2001 06 29  |
| Purpose  |
If the user presses Tab or Return key, we do navigation purpose in the grid. Additionally we call 'SetEditMode' after navigating.  |
| In parameters  | Default VB event parameters.  |
| Procedure 'txt_KeyPress' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  | KeyAscii As Integer  |
| Author  | Ralf Kunsmann  |
| Date  | 2001 05 03  |
| Purpose  |
If the edit mode 'numerical only' (--> 'Create' methode) is set, allow only 1 to 9, point, comma and minus as input characters.  |
| In parameters  | Default VB event parameters.  |
| Procedure 'txt_LostFocus' | List of procedures |
| Scope/Type  | Private Sub  |
|---|
| Procedure 'PrepareTextBox' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 21  |
| Purpose  |
Add TextBox control to the form, the grid is displayed on and prepare the necessary control properties.  |
| Procedure 'PrepareComboBox' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 21  |
| Purpose  |
Add ComboBox control to the form, the grid is displayed on and prepare the necessary control properties.  |
| Procedure 'SetEditMode' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2001 06 29  |
| Purpose  |
Managing the input purpose. If input mode is active (TextBox visible), we copy the input value from the TextBox to the current grid cell and hide the Textbox, else we start the edit mode by placing TextBox to the position and size of the current cell, format the TextBox according to the cell, copying value from grid cell to TextBox, bring the TextBox to front and saving to current cell coordinates.  |
| Procedure 'SetControlPosition' | List of procedures |
| Scope/Type  | Private Function  |
|---|---|
| Code return value  | Boolean  |
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 21  |
| Purpose  |
Set ComboBox or TextBox control to the position according to current cell in grid. If type of control is a ComboBox, the width will be extended for displaying PullDown button.  |
| Return Value  | Boolean: True if setting position was successful, else False.  |
| Procedure 'SetupComboBoxFromGridCell' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 21  |
| Purpose  |
Try the activate the item in ComboBox which contains the same string as the current Grid cell.  |
| Procedure 'DoKeyDownReaction' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  |
KeyCode As Integer Shift As Integer  |
| Author  | Ralf Kunsmann  |
| Date  | 2001 06 29  |
| Purpose  |
If the user presses Tab or Return key, we do navigation purpose in the grid. Additionally we call 'SetEditMode' after navigating.  |
| In parameters  | Default VB event parameters.  |
| Procedure 'GetCancelButton' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 24  |
| Purpose  |
There might be a CommandButton on form which has the property 'Cancel = True'. This would lead to not receiving 'vbKeyEscape' in 'lst_KeyDown()' and 'txt_KeyDown()'. To avoid this, we search for a CommandButton on form which has this property.  |
| Procedure 'SetCancelButton' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  | pfState As Boolean  |
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 24  |
| Purpose  |
If we did find a Cancel CommandButton on form (see 'GetCancelButton()') we set it Cancel property as needed.  |
| In parameters  | Boolean: Recommanded state of Cancel CommandButton  |
| Procedure 'AddActiveEditor' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Code Helper  |
| Date  | 24.02.2003  |
| Purpose  | Increment number of active 'CGridEditor' objects.  |
| Procedure 'RemoveActiveEditor' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Code Helper  |
| Date  | 24.02.2003  |
| Purpose  |
Decrement number of active 'CGridEditor' objects. Ensure number is never negative.  |
| Procedure 'SetActiveRow' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  | piRow As Long  |
| Author  | Code Helper  |
| Date  | 24.02.2003  |
| Purpose  | Set the index of the active row of all 'CGridEditor' objects.  |
| Procedure 'SetRowHeight' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Code parameters  | piRowHeight As Long  |
| Author  | Code Helper  |
| Date  | 24.02.2003  |
| Purpose  | Set the index of the active row of all 'CGridEditor' objects.  |
| Procedure 'GetActiveEditors' | List of procedures |
| Scope/Type  | Private Function  |
|---|---|
| Code return value  | Long  |
| Author  | Code Helper  |
| Date  | 24.02.2003  |
| Purpose  | Get the number of currently active 'CGridEditor' objects.  |
| Result  | Long: Recommand number.  |
| Procedure 'GetActiveRow' | List of procedures |
| Scope/Type  | Private Function  |
|---|---|
| Code return value  | Long  |
| Author  | Code Helper  |
| Date  | 24.02.2003  |
| Purpose  | Get the index of currently row of active 'CGridEditor' object.  |
| Result  | Long: Recommand number.  |
| Procedure 'GetRowHeight' | List of procedures |
| Scope/Type  | Private Function  |
|---|---|
| Code return value  | Long  |
| Author  | Code Helper  |
| Date  | 24.02.2003  |
| Purpose  |
Get the last store RowHeight value from any active 'CGridEditor' object.  |
| Result  | Long: Recommand number.  |
| Procedure 'StopEditing' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 25  |
| Purpose  |
Hide the current edited control and do some other stuff, which is necessary to stop editing.  |
| Procedure 'FinishEditing' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Ralf Kunsmann  |
| Date  | 2003 02 25  |
| Purpose  |
Final stuff which is necessary to stop editing: (Re-)activate grid control or force form to be repainted.  |
| Procedure 'GetTag' | List of procedures |
| Scope/Type  | Private Function  |
|---|---|
| Code parameters  | psTagName As String  |
| Code return value  | String  |
| Author  | Code Helper  |
| Date  | 25.02.2003  |
| Purpose  | Get defined part of grids 'Tag' property.  |
| Result  | String: The hole tag as [Name]=[Value]  |
| In parameters  | String: Name of tag part to be retrieved  |
| Procedure 'SetupTextBoxFromGridCell' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Code Helper  |
| Date  | 25.02.2003  |
| Purpose  |
Set TextBox Text and Alignment properties from current grid cell.  |
| Procedure 'HideEditorControls' | List of procedures |
| Scope/Type  | Private Sub  |
|---|---|
| Author  | Code Helper  |
| Date  | 25.02.2003  |
| Purpose  | Hide TextBox or ListBox Control.  |
| Procedure 'CopyValueToGridCell' | List of procedures |
| Scope/Type  | Private Function  |
|---|---|
| Code return value  | Boolean  |
| Author  | Code Helper  |
| Date  | 25.02.2003  |
| Purpose  | Copy new value from TextBox or ListBox to grid cell.  |
| Return Value  | Boolean: True is value was changed, else False  |