Click to See Complete Forum and Search --> : populate a dropdown list for selection on a dbgrid cell


Suhail
September 20th, 2001, 04:55 AM
hi,

I am trying to populate commonly used data as a list to be shown on a dbgrid cell, so that the user can make a selection just by clicking on the list of data with in that cell. Thus the selected text of list remains the data of the cell when saved.
Can anyone tell me how to populate this.

thanks,
Regards
Suhail

Iouri
September 20th, 2001, 07:14 AM
'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
iouri@hotsheet.com

Suhail
September 21st, 2001, 02:49 PM
Hi, Louri

Thanks for your code. But this is not what I was looking for, well what I wanted is a combolist with in one of a dbgrid cell. If you could help with this.

Thanks
Suhail

Iouri
September 21st, 2001, 03:01 PM
You cannot have a combo instead of the cell. You can enter data to the combo and then position it on the top of the cell. My code is entering data to the combo. Make the combo invisible and on the grid click event resize the combo to the size of the chosen cell and move the combo there.

Iouri Boutchkine
iouri@hotsheet.com

Suhail
September 21st, 2001, 03:35 PM
But what if a user wants to add another row to the dbgrid. How will the combo be created on a new row and if the user updates will the data be updated and saved. Also if the user closes the window on which the grid is and then initiates again how does the lists on all the rows of dbgrid show the exact data which the user last saved.

Thanks for your kind help
Suhail

Iouri
September 21st, 2001, 03:48 PM
You have only one combo on a form and you will move this combo to the cell where user enters/reads data. You cannot enter data into more than 1 cell at the same time anyway. When you click on the different cell, combo moves there.
On combo lost focus event you have to write data to the grid which is bound to the database. When user open the form you have to add data to the combo of this field where the where your focus. See code above.

Iouri Boutchkine
iouri@hotsheet.com

Suhail
September 22nd, 2001, 05:00 AM
Thanks louri, You have shown a great deal of interest to help. I appriciate your kindness and an attitude to help others.

Thanks again
Suhail