|
-
March 20th, 2001, 09:47 PM
#1
Positioning a combo box in a DBGrid cell & making validations
Hi.
I have a dbgrid in my form containing 10 columns displaying records from an Access table. It is required that in the 10th column, instead of the user inputting a value, he/she will select a value from a combo box. This is true for all rows of the 10th column. This will ensure that only valid values will be entered. How can I put the combo box in a particular cell of the 10th column?
My second question concerns validations for those cells that will not use a combo box. Say the numeric input values in a certain column require to be of a certain range only, how can I validate the inputs? What events of the dbgrid will I use to make validations?
Thanks for the info in advance!
-
March 21st, 2001, 08:43 AM
#2
Re: Positioning a combo box in a DBGrid cell & making validations
'Reference: Microsoft ActiveX Data Objects 2.5 Library
'Place this section at top of form
Private WithEvents rsADOSetRecord As ADODB.Recordset
Private adoDataGrid As ADODB.Connection
Private Sub sbLoadCombo()
Set adoDataGrid = New ADODB.Connection
Set rsADOSetRecord = New ADODB.Recordset
With rsADOSetRecord
.Open "SELECT DISTINCT " & strFiledName & " FROM " & strTableName, adoDataGrid, , , adAsyncFetch
If Not .BOF Then
.MoveFirst
Do While Not .EOF
If .Fields(0).Value <> vbNull Then combo1.AddItem .Fields(0).Value
.MoveNext
Loop
End If
.Close
End With
End Sub
Iouri Boutchkine
[email protected]
-
March 21st, 2001, 07:42 PM
#3
Re: Positioning a combo box in a DBGrid cell & making validations
Thanks for the reply. I saved the code you posted for future use. However, my current problem lies in the fact that a dbgrid cannot contain a combo box, so I have to device a method on how to put combo box in the dbgrid cell where the user wishes to make an input, in this case all of the cells of the 10th column. But of course, it will be costly to put a combo box for every cell of the 10th column, and besides, the number of rows needed to retrieve the records from my database will vary. Therefore, a single combo box is employed and will be positioned in the cell that the user chooses; and this is my foremost problem. Any more ideas?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|