Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data input problems

Status
Not open for further replies.

praveensg

Programmer
May 15, 2002
26
GB
Hi,
This is my problem---

I got to have a database with infinite records..i mean we do not know the number of records in it beforehand...i want the user to be able to have a combobox for each record and also some scrolls etc...is it possible to do this with a msflexgrid..are there any major differences between ms and msh flexgrids....does it display combobox for each record
plz guide me...
thanq
praveen
 
The difference between a MS and MSH flexgrid is that the MS one can display a flat recordset where a MSH one can display a hierarchical recordset (or flat). Neither will automatically use a combo box - you will have to program that yourself, and that 'ain't easy!

Some controls make it slightly easier, for instance I have used the Apex TrueDBGrid Pro controls in the past - but you have to buy them and they are still not exactly simple to use.
 
what wud u suggest me to do....this is really important for me...any links or sources would really help me..
thanx
praveen
 
my boss will not allow me to purchase one!!! let it be :(
 
Its not that difficult to place a combo box or a text box on given cell of a FlexGrid.

' Add event handler to catch grid click, and activate the correct control type for that column

Private Sub grdObserve_Click()

Dim lInt_SelRow As Integer
Dim lInt_SelCol As Integer

lInt_SelRow = grdObserve.Row
lInt_SelCol = grdObserve.Col

Select Case lInt_SelCol
Case <column(s) that need combo box>
ActivateComboBox
Case <column(s) that need text box>
ActivateTextBox
End Select

Exit Sub

' Bring the combo box up, set the value, position it, and send the user to it.

Private Sub ActivateComboBox()

Dim lInt_Left As Integer
Dim lInt_Top As Integer
Dim lInt_RowID As Integer
Dim lInt_ColID As Integer

lInt_RowID = grdObserve.Row
lInt_ColID = grdObserve.Col
lInt_Left = grdObserve.Left + grdObserve.CellLeft
lInt_Top = grdObserve.Top + grdObserve.CellTop

cboGrid.Top = lInt_Top - 20
cboGrid.Left = lInt_Left - 20
cboGrid.Tag = lInt_RowID & &quot;,&quot; & lInt_ColID
cboGrid.Text = grdObserve.Text
cboGrid.Visible = True
cboGrid.Enabled = True
cboGrid.SetFocus

Exit Sub

' Stuff the selected value back into the grid, and hide the combo box

Private Sub cboGrid_LostFocus(rInt_CntlID As Integer)

Dim lVar_PrevPos_Arr As Variant
Dim lInt_RowID As Integer
Dim lInt_ColID As Integer

lVar_PrevPos_Arr = Split(cboGrid.Tag, &quot;,&quot;)
lInt_RowID = lVar_PrevPos_Arr(0)
lInt_ColID = lVar_PrevPos_Arr(1)
grdObserve.TextMatrix(lInt_RowID, lInt_ColID) = cboGrid.Text
cboGrid.Visible = False

End Sub

The code for textboxes works in a similar manner

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
The line

Private Sub cboGrid_LostFocus(rInt_CntlID As Integer)

should read

Private Sub cboGrid_LostFocus()

Unless of course you're using control arrays, which is quite useful in some applications
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
... and of course you need to fill your combo box with the relevant data unless you have one for each field.
 
the lostfocus sub is giving me errors at the array value assignment after the split function...subscript out of range...what exactly is the split doing there..
thanq
praveen
 
You have placed in the .Tag property of the combo box, the row and column (separated by a comma) of the grid cell that was clicked on.

That assignment is made in the ActivateComboBox procedure.
cboGrid.Tag = lInt_RowID & &quot;,&quot; & lInt_ColID

The Split function is used to extract that information from the .Tag, and the two assignments that follow copy the information from the array into scalar integer variables that are used in the .TextMatrix method to assign the selected combo box value into the correct cell of the grid.

To help you find the Subscript Out of Range, I'll need to see your code.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
hi,
this is my code..i am using 3 column flexgrid...

Code:
Private Sub Form_Load()
cboGrid.AddItem (&quot;Spec1&quot;)
cboGrid.AddItem (&quot;Spec2&quot;)
cboGrid.AddItem (&quot;Spec3&quot;)
End Sub

Private Sub grdObserve_Click()
   
   Dim lInt_SelRow         As Integer
   Dim lInt_SelCol         As Integer
   
   lInt_SelRow = grdObserve.Row
   lInt_SelCol = grdObserve.Col
   
   Select Case lInt_SelCol
      Case 1
         ActivateComboBox
      'Case <column(s) that need text box>
       '  ActivateTextBox
   End Select
   
End Sub

' Bring the combo box up, set the value, position it, and send the user to it.

Private Sub ActivateComboBox()

   Dim lInt_Left  As Integer
   Dim lInt_Top   As Integer
   Dim lInt_RowID As Integer
   Dim lInt_ColID As Integer

   lInt_RowID = grdObserve.Row
   lInt_ColID = grdObserve.Col
   lInt_Left = grdObserve.Left + grdObserve.CellLeft
   lInt_Top = grdObserve.Top + grdObserve.CellTop

   cboGrid.Top = lInt_Top - 20
   cboGrid.Left = lInt_Left - 20
   cboGrid.Tag = lInt_RowID & &quot;,&quot; & lInt_ColID
   cboGrid.Text = grdObserve.Text
   cboGrid.Visible = True
   cboGrid.Enabled = True
   cboGrid.SetFocus

End Sub

' Stuff the selected value back into the grid, and hide the combo box

Private Sub cboGrid_LostFocus()
   
   Dim lVar_PrevPos_Arr As Variant
   Dim lInt_RowID As Integer
   Dim lInt_ColID As Integer

   lVar_PrevPos_Arr = Split(cboGrid.Tag, &quot;,&quot;)
   lInt_RowID = lVar_PrevPos_Arr(0)
   lInt_ColID = lVar_PrevPos_Arr(1)
   grdObserve.TextMatrix(lInt_RowID, lInt_ColID) = cboGrid.Text
   cboGrid.Visible = False
   
End Sub
 
I don't see anything wrong - put a break point on the line after the split - and put a watch on lVar_PrevPos_Arr, and see what it holds
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
ok - step thru the ActivateComboBox function and insure that the
cboGrid.Tag = lInt_RowID & &quot;,&quot; & lInt_ColID
is executed and that data is properly placed into the tag property of the combo box.

Then in the lost focus, again check the value of cboGrid.Tag and make sure it still has the same values. If not, then something is clearing that value between the cboGrid.SetFocus and the cboGrid_LostFocus event. Do you have any other events (KeyPress, KeyDown, MouseDown, etc) that are in force while the cboGrid has focus?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
what does ur program do centurion...i mean what i want is if i click on a particular cell, the combo has to show up..i will use onlyone combo...and also is it necessary to use Tag property..what does it do exactly.
thanx
praveen
 
What the program does is to put a combo box on top of the grid cell that you clicked on. Then when you leave the combobox, the selected item is placed back into that cell of the grid.

The reason that the .tag property is used is to keep track of which cell was originally clicked on. The cell is being identified by the row and the column. The reason that is necessary is that its possible for the combobox to lose focus because a different cell from the grid was clicked on. Once that happens, the grid will activate the cell that was just clicked on, and not the original cell to which the combobox applies. You don't necessarily have to use the tag property, but you do have to keep that information somewhere, so you know which cell to update.

In design mode - make sure that the combobox and grid have the same container. For example, if the grid is inside a frame, put the combobox inside the same frame. Also, the combobox should be visible on top of the grid when in design mode. If its not, then bring the combo box to the top, or send the grid back. And the initial setting of the visible property of the combobox should be false.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
thanq very much friend...it works now...i do not know what was wrong...now again, i have a problem...when i try to set the datasource property of the flexgrid, it says object variable or with block variable not set...what to do
thanq...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top