ComboBox Binding

stevecking

Active member
Joined
Dec 27, 2006
Messages
32
Programming Experience
5-10
I have a front-end application containing a database which may/or may not get it's data from another database being used as a repository. The comboboxes are currently bound to dataset which are derived from the repository. My problem occurs with the (may not) part of the requirement. If the item doesn't exist in the repository and I'm using SelectedValue binding then the user can't simply type a value into the combobox and click the save button. I've done frequent develoment using Microsoft Access and the combobox control can be programmatically managed to handle this situation and add the value to the source table.

How can this situation be handled in Visual Basic.NET? Can I dual-bind to the Text property? Can I programmatically modify the bindings in the OnKeyDown event? I'm open to any suggestions. Thanks in advance.
 
The DropDownStyle property controls the interface that is presented to the user. You can enter a value that provides a simple drop-down list box, where the list always displays, a drop-down list box, where the text portion is not editable and you must select an arrow to view the drop-down, or the default drop-down list box, where the text portion is editable and the user must press the arrow key to view the list. To always display a list that the user cannot edit, use a ListBox control.

This seems a simple answer but what would the binding bind to? Certainly not SelectedValue.
 
hi
im doing combobox fill without a binding. and with it i can fill from database, or just write it. u maybe can use this syntax yourComboBox.Items.Add(xx) << xx are string or variable that contain string. if string wrap it with "xx".
i give you an example, but sorry it was sql database.

VB.NET:
Imports System.Net

Private ComputerName As String = System.Net.Dns.GetHostName
    Private DatabaseName As String = "Actuator"
    Private MyConnector As String = "Data Source=" & ComputerName & ";Initial Catalog=" _
& DatabaseName & ";Integrated Security=True"
    Private IA_conn As New SqlConnection

'im using this function(GetData) so if i make another program with connection, ill just copy it :p

Public Function GetData(ByVal strq1 As String) As DataSet
        Dim ds As New DataSet

        Try
            If IA_conn.State = ConnectionState.Open Then
                IA_conn.Close()
            End If
            IA_conn.ConnectionString = MyConnector
            IA_conn.Open()
            ' Create a data adapter
            Dim da As New SqlDataAdapter(strq1, IA_conn)
            ' Create DataSet, fill it
            da.Fill(ds, "Tabel")

        Catch ex As Exception

        End Try
        Return ds
    End Function

'this is filling Combobox with database
  Public Sub Filling_Combobox()
        Dim IA_dsAct2 As New DataSet
        IA_dsAct2 = GetData("select distinct posisi from Actuator")

        Dim i1 As Integer
        For i1 = 0 To IA_dsAct2.Tables(0).Rows.Count - 1
            Dim isia3 As String = IA_dsAct2.Tables(0).Rows(i1).Item("posisi")
            CB_EI_Posisi.Items.Add(isia3)
        Next

    End Sub
i hope this help u a little ;)
 
Last edited by a moderator:
Back
Top