CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2001
    Posts
    4

    populate a dropdown list for selection on a dbgrid cell

    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


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: populate a dropdown list for selection on a dbgrid cell

    '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]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Sep 2001
    Posts
    4

    Re: populate a dropdown list for selection on a dbgrid cell

    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


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: populate a dropdown list for selection on a dbgrid cell

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Sep 2001
    Posts
    4

    Re: populate a dropdown list for selection on a dbgrid cell

    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


  6. #6
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: populate a dropdown list for selection on a dbgrid cell

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

  7. #7
    Join Date
    Sep 2001
    Posts
    4

    Re: populate a dropdown list for selection on a dbgrid cell

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured