CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2000
    Posts
    292

    Dynamically positioning a combo box in a DBGrid cell

    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!


  2. #2

    Re: Dynamically positioning a combo box in a DBGrid cell

    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....


  3. #3
    Join Date
    Mar 2000
    Posts
    292

    Re: Dynamically positioning a combo box in a DBGrid cell

    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?


  4. #4

    Re: Dynamically positioning a combo box in a DBGrid cell

    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.


  5. #5
    Join Date
    Mar 2000
    Posts
    292

    Re: Dynamically positioning a combo box in a DBGrid cell

    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.


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