Results 1 to 3 of 3

Thread: [RESOLVED] combo box binding problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Resolved [RESOLVED] combo box binding problem

    hi all,

    i'm having a problem binding my combo box to my data table

    i have these codes that binds my combo box.

    Code:
    combo.DataBindings.Add("Text", DataTable, "status")
    this code works well only when reading data... it automatically selects the correct item in my combo box to whatever was saved to that column in my table... however, when editing or updating the combo box text, it doesn't update.

    so then i tried these codes

    Code:
    combo.DataSource = Datatable
    combo.DisplayMember = "status"
    combo.Items.Add("MARRIED")
    combo.Items.Add("SINGLE")
    combo.Items.Add("WIDOWED")
    unfortunately this won't work with the reading and updating.
    considering that i have all my adapter insert, update, delete command set already and are actually working with databinds in a textbox control.

    any thoughts? thanks...
    Last edited by adshocker; Jul 28th, 2007 at 07:48 PM.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: combo box binding problem

    The ComboBox supports both types of binding: complex and simple. It supports complex binding via its DataSource property, and it supports simple binding like any other control via its DataBindings collection. You first have to decide what type or types of binding you need to implement. In your case it should be simple binding. If your list of marital statuses is drawn from a database table then you'd use complex binding too, but I don't think that's the case here.

    The first step is to add the list of items to the ComboBox. If you're using a predefined list of strings then you should be adding them in designer. If it's an unknown list of strings or a list of some other type then you should add them in code, e.g.
    vb.net Code:
    1. combo.Items.Add("MARRIED")
    2. combo.Items.Add("SINGLE")
    3. combo.Items.Add("WIDOWED")
    You should also be setting the DropDownStyle property to DropDownList in the designer.

    Now you need to apply your simple binding. The idea here is that the item selected in the ComboBox corresponds to 'status' field in the DataRow:
    vb Code:
    1. combo.DataBindings.Add("SelectedItem", DataTable, "status")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: combo box binding problem

    i see... thanks much.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

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