Combobox properties

Glenn Walker 251 Reputation points
2021-04-09T20:52:37.187+00:00

I want to be able to input an item into a combobox that is data bound. If this is possible.

I have a combobox that is bound to a table. I use this combobox to display a set of items from a table, each of which defines a type of document, e.g., SOP, Drawing.

                cboDoc.Enabled = True
                cboDoc.TabIndex = 2
                cboDoc.TabStop = True
                cboDoc.DataSource = DocBindingSource
                cboDoc.ValueMember = "DocType"
                cboDoc.DisplayMember = "DocType"

With the above property settings this combobox allows the user to select one of the document types to later input into a record.

What I want to do, in addition to this is two things. The first is for the user to be able to input a value to the record. The properties, as set, already allow for this.

The second is to be able to save the input string value back into the table bound to the combobox.

I have not been able to uncover how this is done with my current review of material and/or queries.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,594 questions
0 comments No comments
{count} votes

Accepted answer
  1. Glenn Walker 251 Reputation points
    2021-04-11T03:30:09.727+00:00

    OK, I have a working solution for saving an input to bound combobox table. While it works, and I will find myself a better handler, I really believe that there must be a better way than that. It seem so.... klugey.

    Anyway, with this I am able to add items to lkpDoc from the Combobox.

        Private Sub AddDocType_Click(sender As Object, e As EventArgs) Handles cboDoc.Leave
            Dim CurrentRecord = 0
            MasterBase.AddParam("@doc", cboDoc.Text)
            MasterBase.MasterBaseQuery("INSERT INTO lkpDoc (DocType) " &
                                       "VALUES (@doc); ")
            CurrentRecord = MasterBase.ListTable.Rows.Count - 1
            MasterBase.AddParam("@doc", cboDoc.Text)
            MasterBase.AddParam("@recno", CurrentRecord)
            MasterBase.MasterBaseQuery("UPDATE lkpDoc " &
                                       "SET DocType=@doc " &
                                       "WHERE ID=@recno ")
            'Report & Abort on errors
            If NoErrors(True) = False Then Exit Sub
        End Sub
    
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2021-04-10T10:53:27.813+00:00
    0 comments No comments

  2. Glenn Walker 251 Reputation points
    2021-04-10T15:10:11.863+00:00

    I don't think so, but I could be. My problem is just as soon as I think I understand comboboxes I find that I actually know nothing. Here is where I am at so far:

    This is what I have kluged together so far. Kind of works, but I end up with two additions to the lkpDoc table. A work in progress.

        Private Sub AddDocType_Click(sender As Object, e As EventArgs) Handles cboDoc.Leave
            Dim RecordCount = 0
            MasterBase.AddParam("@doc", cboDoc.Text)
            MasterBase.MasterBaseQuery("INSERT INTO lkpDoc (DocType) " &
                                       "VALUES (@doc); ")
            RecordCount = MasterBase.ListAdapter.Fill(MasterBase.ListTable)
            MasterBase.AddParam("@doc", cboDoc.Text)
            MasterBase.MasterBaseQuery("UPDATE lkpDoc " &
                                       "SET DocType=@doc " &
                                       "WHERE ID=RecordCount ")
            'Report & Abort on errors
            If NoErrors(True) = False Then Exit Sub
        End Sub
    
    0 comments No comments