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!

using Combo Box with Grid controls ???

Status
Not open for further replies.

miq

Programmer
Apr 24, 2002
315
PK
hi,
I want to use combo box rather then simple text box bacause there are few possible correct values exists.
How can i achieve this.

Bye

 
Miq,

I would use the ItemData of the ComboBox Properties to set the ID for each piece of data and then call it in your code from there. In your code you can call the data to be displayed by number or actual object name. I'm not sure but the code might look something like this:

Private Sub Combo1_Click
MSFlexGrid.Data1 = First Data piece
MSFlexGrid.Data2 = Second Data piece
and so on

Hope this helps some
Nikotnby
 
hi,
I am using MSFlexGrid Control
 
hi,
I need to let user select an option from combo or lit box while working with MsFlexGrid. when uer select specific cell he must be presented with combo/list box where he can select his option

How can i achieve this??


Bye
 
Unfortunately, the FlexGrid does not allow for direct editing. But there is a workaround. There are several steps for this.

1) Create a combobox on the form in the same container as the FlexGrid. Set the .Visible property of the combobox to false. Insure that the combobox is in front of the grid.

2) Then drop in the following code. What happens is that the user clicks on a cell, the value of the cell is copied into the combobox, the combobox is positioned on top of the cell, made visible, and given focus. In the lost focus, the selected value is copied from the combobox backup into the cell, and the combobox is made invisible again.

Private Sub grdGrid_Click()

Select Case grdGrid.Col
Case 1, 3, 4 ' <List of Columns that Use Text Boxes>
ActivateTextBox
Case 2, 5, 6 ' <List of Columns that Need Combo Box>
ActivateComboBox
End Select

End Sub

Private Sub ActivateComboBox()

cboCombo.Top = grdGrid.Top + grdGrid.CellTop - 20
cboCombo.Left = grdGrid.Left + grdGrid.CellLeft - 20
cboCombo.Width = grdGrid.CellWidth
cboCombo.Tag = grdGrid.Row & &quot;,&quot; & grdGrid
cboCombo.Text = grdGrid.Text
cboCombo.Visible = True
cboCombo.Enabled = True
cboCombo.SetFocus

End Sub

Private Sub cboCombo_LostFocus()

Dim PrevPos_Arr As Variant
Dim RowID As Integer
Dim ColId As Integer

PrevPos_Arr = Split(cboCombo.Tag, &quot;,&quot;)
RowID = PrevPos_Arr(0)
ColId = PrevPos_Arr(1)
grdGrid.TextMatrix(RowID, ColId) = cboCombo.Text
cboCombo.Visible = False

End Sub

As you can see, you can also use the same technique with text boxes over those cells which would require a text box for updating.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
I have copied and pasted the code that you have provided several months ago. The problem I am having tho is that the combo box continues to display behind the FlexGrid.

Any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top