Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to Update Binded Combobox value ?

How to Update Binded Combobox value ?

Scheduled Pinned Locked Moved Visual Basic
helpcsharpdatabasesql-server
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rashadaliarshad
    wrote on last edited by
    #1

    I am facing problems to update combo box value that is binding to a datasource ... i m using VB.NET 2005 and SQL SERVER 2000 at back. I simply created a Data Source. And added 'PurchaseOrders' Table in it. Set it to draw 'DETAILS' components. and dragged it on to the form and it draws all the controls on the form. along with a navigator and binding source, dataset added to the form. Now i have a field ... SUPPLIER ID and its component was set to a COMBOBOX. I seprately loaded this combobox with a datasource as: SupplierIDCombobox.Datasource = DsSupplier.Tables(0) SupplierIDCombobox.DisplayMember = "SupplierName" SupplierIDCombobox.ValueMember = SupplierID now when i run the program, the first SupplierID is picked by the combobox correctly. When i navigate to second purchase Order. the supplierID does not change. How to fix this problem??? anyone?

    :- Rashid Ali -:

    D 1 Reply Last reply
    0
    • R rashadaliarshad

      I am facing problems to update combo box value that is binding to a datasource ... i m using VB.NET 2005 and SQL SERVER 2000 at back. I simply created a Data Source. And added 'PurchaseOrders' Table in it. Set it to draw 'DETAILS' components. and dragged it on to the form and it draws all the controls on the form. along with a navigator and binding source, dataset added to the form. Now i have a field ... SUPPLIER ID and its component was set to a COMBOBOX. I seprately loaded this combobox with a datasource as: SupplierIDCombobox.Datasource = DsSupplier.Tables(0) SupplierIDCombobox.DisplayMember = "SupplierName" SupplierIDCombobox.ValueMember = SupplierID now when i run the program, the first SupplierID is picked by the combobox correctly. When i navigate to second purchase Order. the supplierID does not change. How to fix this problem??? anyone?

      :- Rashid Ali -:

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      OK. There's a few things you have to do. First, you need a second BindingSource and set it's DataSource and DataMember properties to the table that's going to supply the ID's and Text for the ComboBox to show. It helps greatly if the DataSet you're using has both the table that you're already showing and the table that's supplying the data for the ComboBox. There's normally a one-to-many relationship between these two tables. The DataSource property of the ComboBox needs to be set to the BindingSource you just created. Also set it's DisplayMember to the field that's supplying the Text the user gets to see in the Combo and set the ValueMember property to the field that's supplying the ID's for those text items. Then, create a new Binding object and add it to the DataBindings property of the ComboBox. This binding needs to bind the SelectedValue property of the ComboBox to the original BindingSource you already have on the form and the name of the field in that bindingsource that's going to hold the value selected in the ComboBox.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      R 1 Reply Last reply
      0
      • D Dave Kreskowiak

        OK. There's a few things you have to do. First, you need a second BindingSource and set it's DataSource and DataMember properties to the table that's going to supply the ID's and Text for the ComboBox to show. It helps greatly if the DataSet you're using has both the table that you're already showing and the table that's supplying the data for the ComboBox. There's normally a one-to-many relationship between these two tables. The DataSource property of the ComboBox needs to be set to the BindingSource you just created. Also set it's DisplayMember to the field that's supplying the Text the user gets to see in the Combo and set the ValueMember property to the field that's supplying the ID's for those text items. Then, create a new Binding object and add it to the DataBindings property of the ComboBox. This binding needs to bind the SelectedValue property of the ComboBox to the original BindingSource you already have on the form and the name of the field in that bindingsource that's going to hold the value selected in the ComboBox.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        R Offline
        R Offline
        rashadaliarshad
        wrote on last edited by
        #3

        . . . you need a second BindingSource and set it's DataSource and DataMember properties to the table that's going to supply the ID's and Text for the ComboBox to show. I wrote code manually to get get ID and Name fields from database. here is the code. Private Sub LoadSuppliers() m_CommandSupplier = New SqlCommand m_CommandSupplier.CommandText = "Select SupplierId, SupplierName from Suppliers" Try m_DaSupplier = New SqlDataAdapter m_DaSupplier.SelectCommand = m_CommandSupplier _**// connection has already been created in seprate Sub-Routine**_ m_DaSupplier.SelectCommand.Connection = m_ConnectionSupplier m_DsSupplier = New DataSet() m_DaSupplier.Fill(m_DsSupplier) Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical, " Get Suppliers") End Try m_DsSupplier.Tables(0).TableName = "Suppliers" **1 - it's DisplayMember to the field that's supplying the Text the user gets to see in the Combo and set the ValueMember property to the field that's supplying the ID's for those text items.** **2 - create a new Binding object and add it to the DataBindings property of the ComboBox** _Both these task are accomplished in the following code, SupplierNAme is set as Display MEmber , while the SupplierID is set a value member._ With SupplierIDComboBox .DataSource = mDsSupplier.Tables("Suppliers") .DisplayMember = "SupplierName" .ValueMember = "SupplierId" .DataBindings.Clear() .DataBindings.Add("SelectedValue", PurchaseOrderDetailsDataSet.PurchaseOrders, "SupplierId") End With End Sub the table that's supplying the data for the ComboBox. There's normally a one-to-many relationship between these two tables. The Table that supply the value for both tables is actually a Binding Source with a binding navigator to move back and forth. All these were automatically drawn when i dragged the 'PurchaseOrder' Table from Datasources window. Note: 'PurchaseOrder' table was set to draw control in 'DETAILS mode' while "PurchaseOrderDetails" table was set to 'DAtagridview mode'. Now when i run the program, the value for PurchaseOrder and PurchaseOrderDetails tables in both Details and datagrid goes fine. But when i click 'MOVE NEXT RECORD' button from BINDING NAVIGATOR. All the values in Tex

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups