Click to See Complete Forum and Search --> : Dynamically positioning a combo box in a DBGrid cell


daneb
March 15th, 2001, 07:45 PM
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 position the combo box whenever the user wish to input in any of the rows of the 10th column?

My other question is that, how can I present in the dbgrid numeric values similarly as they appear in the database? For instance, if the value is 1,234.00, the dbgrid must present this as 1,234.00 also. And if a value is required to be of the Date/Time type (mm/dd/yyyy), how does validation occur?

Thanks for the info in advance!

robby bassic
March 16th, 2001, 12:39 AM
Part 1
'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

Part 2

in the DBgrid properties(custom) there is a format section. You can set date, yes/no, etc....

daneb
March 16th, 2001, 02:16 AM
Thanks for the reply.

For my 2nd question first, where will I set the format of the data to be displayed in the dbgrid? I opened the Properties dialog box and noticed that in the Columns tab, the Column combo box defaults to only 2 columns, I have more than this. How can I set the format for each column?

Then for my 1st question, my problem is how to put the combo box in the cell that I select or click. My combo box already has items in it. It will be expensive if I will put a combo box for every cell in the 10th column, so I just have to vary the position/location of a single combo box depending upon where the user clicked.

Any more suggestions?

robby bassic
March 16th, 2001, 12:40 PM
First put a Data1 control on your form, connect to an MDB. then set DataSource of the DBGrid to Data1. (You can remove the this later)
While in design view, right click on the DBGrid and select "Retrieve fields" . then all the fields that the grid is connected to will show up. You can then set the properties to each field.

As for populating the combo box; I missunderstood the question.
I'll get back to you today about that.

daneb
March 22nd, 2001, 01:09 AM
Thanks again for the reply. Sorry responding late. It was only yesterday that I learned what the "Retrieve Fields" option in the popup menu is for. When I tried it, you're right. All of the fields that I set in the Data control were retrieved and I was able to set the properties of each column.

Thanks for the support.