473,509 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I change the selected item in a listbox according to a Comb

How do I change the selected item in a listbox according to a Combox's
selected item on the same form? The Combox is from a different table in the
same dataset as the Listbox uses. Combox's ValueMember is a ID that is a
column in the table that the listbox uses. Is there a way to link these 2's
relation so that when the user changes the selection in the Combox the list
box would automacticall changes to reflect the items that's linked to the
combox selection?

Thanks, Alpha
Nov 17 '05 #1
2 3311
The simplest way is to create a binding between the two with
DataBindings.Add() which is accessible as a property of the control that you
want to automatically update.

A simple example of this would be a ListBox and a ComboBox bound to the same
data, in order to have the SelectedValue in the ListBox be the same as what
the ComboBox has been set to, you would simply do the following:

listBox1.DataBindings.Add("SelectedValue", comboBox1, "SelectedValue");

The above example assumes that the property specified by the ValueMember of
both controls is the same and unique within the list.

Brendan
"Alpha" wrote:
How do I change the selected item in a listbox according to a Combox's
selected item on the same form? The Combox is from a different table in the
same dataset as the Listbox uses. Combox's ValueMember is a ID that is a
column in the table that the listbox uses. Is there a way to link these 2's
relation so that when the user changes the selection in the Combox the list
box would automacticall changes to reflect the items that's linked to the
combox selection?

Thanks, Alpha

Nov 17 '05 #2
Thank you. I'll give it a try.

"Brendan Grant" wrote:
The simplest way is to create a binding between the two with
DataBindings.Add() which is accessible as a property of the control that you
want to automatically update.

A simple example of this would be a ListBox and a ComboBox bound to the same
data, in order to have the SelectedValue in the ListBox be the same as what
the ComboBox has been set to, you would simply do the following:

listBox1.DataBindings.Add("SelectedValue", comboBox1, "SelectedValue");

The above example assumes that the property specified by the ValueMember of
both controls is the same and unique within the list.

Brendan
"Alpha" wrote:
How do I change the selected item in a listbox according to a Combox's
selected item on the same form? The Combox is from a different table in the
same dataset as the Listbox uses. Combox's ValueMember is a ID that is a
column in the table that the listbox uses. Is there a way to link these 2's
relation so that when the user changes the selection in the Combox the list
box would automacticall changes to reflect the items that's linked to the
combox selection?

Thanks, Alpha

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
22594
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the...
3
3525
by: Alpha | last post by:
I have 3 radio buttons for include, exclued or 'select all' from the listbox items. If a user selects the 'Select All' button' then all items in listbox is hi-lited as selected. Now, when user...
6
6125
by: David De Cotis | last post by:
Hello all, I am trying to go through a ListBox and verify if am item was selected. If an item was selected, I would like to get a handle of the item and simply do a response.write on the selected...
1
4916
by: Karen Grube | last post by:
Hi! I'm using a standard server side ASP.Net listbox control on a web form. The page is basically various shades of green. The listbox itself has a pale green background and forest green text...
2
2747
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected....
3
19049
by: Mitch | last post by:
Is the following a correct representation of the relationship of the selected index to selected item: INDEX ITEM 0 "item 1" 1 "item 2" 2 "item 3" and so on. I keep...
4
6116
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
2
2584
by: remya1000 | last post by:
i'm using VB.NET. i have a table names "EMP". this table contain employee details like Index, empID, First name, Last name, address, phone number etc. while page loads, i need to display Last...
3
29296
by: CSharper | last post by:
Is it possible to selectivly change the color of an item in text. I saw ForeColor option, but it changes the color of all the items. If it is not possible, is there any other control list listbox...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.