Form1: Main form
Form2: English language
Form3: Arabic language
Introduction
With beautiful VB6, I have some trials to edit something like invoice, I found Data grid not familiar to edit tables, also Flex grid has no method to edit. Now I create my ActiveX control using (MSFlexGrid
) control, a hidden text box and a hidden combo box. I give the name (VB6Flexgrid
) to my ActiveX. I create a project (prjFlexGrid
) to test my control. I write the code under Visual Basic 6. With my ActiveX control, you can:
- Edit any cell in flex grid
- Delete any row
- Delete all rows and begin with one row
- Add combo box to any column and use more than one
- Write data to any cell
- Read data from any cell
- Read all data from the grid
Background
When using my ActiveX control (VB6Flexgrid
), the flex grid begins with one row as Data grid control, then increases rows one by one after editing the previous row. My ActiveX control has some methods and some properties:
Method/Property
|
Definition
|
Example
|
ColWidth(anyCol) |
Set column width in (Twip) |
VB6Flexgrid1.ColWidth(1) = 1500 |
TextMatrix(anyRow, anyCol) |
Get or set string for the cell (row, col) |
VB6Flexgrid1.TextMatrix(3, 2) = “VB6” |
CellType anyCol, B |
Let Column include combo box if B = True |
VB6Flexgrid1.CellType 3, True |
ComboClear anyCol |
Clear combo box |
VB6Flexgrid1.ComboClear 3 |
ComboAddItem anyCol, anyString |
Add item to combo box |
VB6Flexgrid1.ComboAddItem 3, “Visual Studio” |
DelRow |
Delete current row |
VB6Flexgrid1.DelRow |
DelAll |
Clear the grid |
VB6Flexgrid1.DelAll |
To use my ActiveX (VB6Flexgrid
), you must add the file VB6Flexgrid.ocx and MicrosoftFlexGrid control to ‘ToolBox’ as follows:
- Click ‘ToolBox’, then choose Components.
- From Components dialog, choose Microsoft FlexGrid Control 6.0.
- Click ‘Browse’ then choose ‘VB6FlexGrid.ocx’ ActiveX control from where you had saved, then click ‘OK’.
Using the Code
About columns:
VB6Flexgrid1.FixedCols = 0
VB6Flexgrid1.Cols = 5
VB6Flexgrid1.ColWidth(1) = 1500
VB6Flexgrid1.ColAlignmentHeader(1) = flexAlignCenterCenter
VB6Flexgrid1.ColAlignment(1) = flexAlignLeftCenter
About combo box:
Set combo box at any column:
VB6Flexgrid1.CellType 3, True
VB6Flexgrid1.ComboClear 3
VB6Flexgrid1.ComboAddItem 3, „Visual Studio“
About cell:
VB6Flexgrid1.TextMatrix(2, 3) = „VB6“
Dim strCell As String
strCell = VB6Flexgrid1. TextMatrix(3, 2)
You can go back to source files of the project (prjFlexGrid
) to read more than the previous examples.
Remarks
When extracting the file VBFlexGrid.zip, you can find the file: ..\VBFlexGrid\ActiveXcontrol\VB6Flexgrid.ocx, find the project to test the ActiveX control in the folder: ..\ VBFlexGrid.
This project has three forms:
Form1
: To choose language
Form2
: For English language
Form3
: For Arabic language
Form2
and Form3
have the same controls:
- The ActiveX control (
VB6Flexgrid1
) adds the file VB6Flexgrid.ocx
- The button control (
btnDelOne
) to delete one row
- The button control (
btnDelAll
) to clear the grid
- The button control (
btnWriteCell
) writes data to the first cell
- The button control (
btnReadOne
) to read the current cell
- The button control (
btnReadAll
) to copy all data from grid to list box
- The button control (
btnExit
) closes the form
- The list box control (
lstAllData
) holds data from grid
Last Words
I hope this article is useful and helps you to create your applications. If you have any ideas or if you find any problems, please tell me. Thanks to CodeProject and thanks to all.
-- Mostafa Kaisoun