|
-
Jul 28th, 2007, 07:37 PM
#1
Thread Starter
Hyperactive Member
[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
-
Jul 28th, 2007, 07:56 PM
#2
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:
combo.Items.Add("MARRIED")
combo.Items.Add("SINGLE")
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:
combo.DataBindings.Add("SelectedItem", DataTable, "status")
-
Jul 28th, 2007, 08:21 PM
#3
Thread Starter
Hyperactive Member
Re: combo box binding problem
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|