Link to home
Start Free TrialLog in
Avatar of BirdsOfFire1
BirdsOfFire1

asked on

Adding records to a Flexgrid from a Combo Box

I am using VB 6.0 with WIN 2000 operating system.  I want to populate a small flexgrid consisting of only two columns of data from a combo box having only two columns. When the user clicks on the command button event, the textbox fields of Column 1 and Column 2 of the combo box  must be added to the flexgrid.  When a second selection value is placed in the textbox of the combo box and the user presses the command button, Column 1 and Column 2  data of the combo box should be added to the flexgrid.  The user should now see the following data in the flexgrid:

      Facility                   Description  
          1                        Warehouse
          2                       Administration


If the user continues to list new data in the combo box and press the command button to add the data to the flexgrid, the system should add the next facility number and description to the flexgrid.  The user should then have the following result in the flexgrid:

      Facility                   Description  
          1                        Warehouse
          2                       Administration
          3                        Detail Center


Private sub Command1_click()

With FacilityFlexgrid
  .FixedRows = 1   'this sets aside the first row for the column Titles & headers
  .FormatString = BuildingNames  ' Building Names is a string variable containing Titles of the flexgrid.
 
  .RowSel = .Rows - 1  'This code determines number of rows in the FacilitiyFlexgrid and then subtracts 1. One is subtracted because the flexgrid starts at zero.  This code should put me on the last row of the flexgrid.
 
   FacilityFlexgrid.TextMatrix(FacilityFlexgrid.RowSel + 1, 0) = cbo_facilities.Column(0)
   FacilityFlexgrid.TextMatrix(FacilityFlexgrid.RowSel + 1, 1) = cbo_facilities.Column(1)
                           'The code above takes the first value of the combo box and put it in the next row of the Flexgrid.  The same with the second line.

End With


This Code only puts the record on row one in the flexgrid.  When user presses the command button for the next record to be placed in the flexgrid, it replaces what is already there.


Thanks,
The FireBird





Avatar of PaulHews
PaulHews
Flag of Canada image

With FacilityFlexgrid
 .FixedRows = 1   'this sets aside the first row for the column Titles & headers
 .FormatString = BuildingNames  ' Building Names is a string variable containing Titles of the flexgrid.
 .Rows = .Rows + 1 'ADDED LINE TO ADD A ROW
 .RowSel = .Rows - 1  'This code determines number of rows in the FacilitiyFlexgrid and then subtracts
1. One is subtracted because the flexgrid starts at zero.  This code should put me on the last row of
the flexgrid.
 
  FacilityFlexgrid.TextMatrix(FacilityFlexgrid.RowSel + 1, 0) = cbo_facilities.Column(0)
  FacilityFlexgrid.TextMatrix(FacilityFlexgrid.RowSel + 1, 1) = cbo_facilities.Column(1)
                          'The code above takes the first value of the combo box and put it in the
next row of the Flexgrid.  The same with the second line.

End With
You could also store the last row in a variable instead of selecting it using rowsel

dim intLastRow as integer
With FacilityFlexgrid
 .FixedRows = 1   'this sets aside the first row for the column Titles & headers
 .FormatString = BuildingNames  ' Building Names is a string variable containing Titles of the flexgrid.
 Rows = .Rows + 1 'ADDED LINE TO ADD A ROW
 intLastRow = .Rows - 1  'This code determines number of rows in the FacilitiyFlexgrid and then subtracts
1. One is subtracted because the flexgrid starts at zero.  This code should put me on the last row of
the flexgrid.
 
  FacilityFlexgrid.TextMatrix(intLastRow+ 1, 0) = cbo_facilities.Column(0)
  FacilityFlexgrid.TextMatrix(intLastRow + 1, 1) = cbo_facilities.Column(1)
                          'The code above takes the first value of the combo box and put it in the
next row of the Flexgrid.  The same with the second line.

End With
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial