Click here to Skip to main content
Click here to Skip to main content

Edit Flex Grid with Combo Box in VB 6

By , 29 Jan 2009
 
Screenshot - Imag5.jpg
Form1: Main form

Screenshot - Imag6.jpg

Form2: English language

Screenshot - Imag7.jpg

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:

' Set number of columns:
VB6Flexgrid1.FixedCols = 0 ' if you do not need fixed columns 
VB6Flexgrid1.Cols = 5 ' number of columns
' Set width of column:
VB6Flexgrid1.ColWidth(1) = 1500 ' width in Twip
' Set alignment of column (You can change many using loop)
VB6Flexgrid1.ColAlignmentHeader(1) = flexAlignCenterCenter 
				' alignment of fixed row, column #1 (to Center)
VB6Flexgrid1.ColAlignment(1) = flexAlignLeftCenter ' alignment column #1 (to Left)

About combo box:

' Set combo box at any column:
VB6Flexgrid1.CellType 3, True  ' combo box at column #3
VB6Flexgrid1.ComboClear 3 ' clear this combo
VB6Flexgrid1.ComboAddItem 3, „Visual Studio“ ' add item to this combo

About cell:

' Send data to any cell:
VB6Flexgrid1.TextMatrix(2, 3) = „VB6“
' Read any cell:
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionSource CodememberMember 849278018-Dec-11 0:19 
AnswerRe: Source CodememberMostafa Kaisoun18-Dec-11 18:37 
GeneralRe: Source CodememberMember 849278018-Dec-11 18:55 
GeneralRe: Source Codememberijkrish22-Oct-12 23:07 
GeneralRe: Source CodememberMostafa Kaisoun23-Oct-12 2:18 
GeneralMy vote of 5memberMember 849278015-Dec-11 13:53 
GeneralThanks.memberashok28011-Apr-11 5:00 
GeneralRe: Thanks.memberMostafa Kaisoun1-Apr-11 12:47 
GeneralIt is really nice to have such code. I am really very thank full to you.memberMember 767804416-Feb-11 0:35 
GeneralRe: It is really nice to have such code. I am really very thank full to you.memberMostafa Kaisoun16-Feb-11 8:16 
GeneralMy vote of 1memberaaahc1-Nov-10 3:50 
GeneralMy vote of 5membermughaljee1-Jul-10 9:15 
GeneralHi, Please do me a favormemberrycopiero17-Jun-10 18:32 
GeneralRe: Hi, Please do me a favormemberMostafa Kaisoun17-Jun-10 23:33 
GeneralRe: Hi, Please do me a favormemberrycopiero18-Jun-10 3:05 
GeneralEditable Grid Control With Support for Combo Boxes and Check Boxes with source.memberrarmas26-Feb-10 3:50 
GeneralRe: Editable Grid Control With Support for Combo Boxes and Check Boxes with source.memberMostafa Kaisoun2-Mar-10 12:54 
GeneralPlease send me source code for vb6flexgrid controlmemberMember 391049619-Dec-09 7:50 
GeneralRe: Please send me source code for vb6flexgrid controlmemberMostafa Kaisoun26-Feb-10 11:35 
GeneralRe: Please send me source code for vb6flexgrid controlmembershganainy18-Feb-11 17:39 
Generalhoimemberjuetiezhernandez20-Oct-09 20:34 
GeneralRe: hoimemberMostafa Kaisoun21-Oct-09 4:30 
QuestionHOW TO CHANGE FONT AND SIZEmemberPeter Wallace13-Oct-09 19:31 
AnswerRe: HOW TO CHANGE FONT AND SIZEmemberMostafa Kaisoun14-Oct-09 18:20 
GeneralRe: HOW TO CHANGE FONT AND SIZEmemberPeter Wallace16-Oct-09 17:27 
AnswerRe: HOW TO CHANGE FONT AND SIZEmemberMostafa Kaisoun17-Jun-10 23:34 
QuestionCan we use VB6Flexgrid.ocx in .NETmemberaarujana24-Jun-09 20:37 
AnswerRe: Can we use VB6Flexgrid.ocx in .NETmemberMostafa Kaisoun25-Jun-09 9:05 
GeneralPls post source code of activex controlmemberAvinash Sureka7-Jun-09 22:36 
QuestionThanks for your ActiveX (VB6Flexgrid)membermigooo3-Jun-09 6:54 
AnswerRe: Thanks for your ActiveX (VB6Flexgrid)memberMostafa Kaisoun3-Jun-09 13:47 
QuestionHow to have a Column as Read Only in this FlexGridmemberVani Agrawal24-Nov-08 19:57 
AnswerRe: How to have a Column as Read Only in this FlexGridmemberMostafa Kaisoun26-Nov-08 12:01 
GeneralRe: How to have a Column as Read Only in this FlexGridmemberamarnath grandhi28-Nov-08 0:19 
GeneralRe: How to have a Column as Read Only in this FlexGridmemberMostafa Kaisoun29-Nov-08 7:55 
GeneralEditable Flex Gridmembercuteshree31-Oct-08 0:35 
GeneralAuto add new linememberMostafa Kaisoun31-May-08 22:03 
GeneralPrevent adding new row automaticallymemberMonjur Ahmed31-May-08 19:38 
GeneralTo hide my name and email [modified]memberMostafa Kaisoun31-May-08 13:09 
GeneralRe: To hide my name and emailmemberKishore.P28-Jan-09 19:30 
GeneralRe: To hide my name and emailmemberMostafa Kaisoun29-Jan-09 13:56 
GeneralReturn ColWidth not availablememberMostafa Kaisoun1-May-08 21:12 
QuestionColWidth produces errormemberkelli329-Apr-08 5:52 
QuestionVB6 FlexGrid require to work with VBAmemberIlyas Kazi6-Mar-08 18:25 
QuestionWhere I can download it??memberale5006-Dec-07 6:09 
GeneralWorkaround neededmemberVidya Amar23-Nov-07 2:26 
GeneralRe: Workaround neededmemberMostafa Kaisoun23-Nov-07 23:51 
GeneralRe: Workaround neededmemberVidya Amar24-Nov-07 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 29 Jan 2009
Article Copyright 2007 by Mostafa Kaisoun
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid