473,770 Members | 1,700 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 3330
The simplest way is to create a binding between the two with
DataBindings.Ad d() 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.DataBi ndings.Add("Sel ectedValue", 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.Ad d() 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.DataBi ndings.Add("Sel ectedValue", 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
22623
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 text of the selected item ? Pete
3
3542
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 selects one item out of the 'all selected' listing then there is now only one item selected. How and where can I put in some code to change the selected radio button to the 'include' since it is no longer in select all mode. Thanks, Alpha
6
6145
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 handle. The issue that I am facing is that I am going each item, but my code does not catch the selected item. Can anyone please take a look at the code and let me know what I am doing wrong.
1
4950
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 and a forest green border. However, when you move the cursor from one item to the next within the listbox or you click on an item in the listbox to select it, the background turns to the standard windows dark blue with white letters. Well, that...
2
2761
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. How can I show those selected items at the top of my listbox. The issue is when the user selects an item and it is in the middle of the list, the user is not able to know an item it is selected or not unless they scroll through the listbox.
3
19082
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 getting the same string for selected index 0 and 1; i.e. both are "item 1". I'm new to C# and not exactly an accomplished programmer. Any suggestions?
4
6140
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 extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub Page_Load(..........) Dim dSet As DataSet Dim sqlConn As SqlConnection
2
2597
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 name First name of all employees in a listbox. and if i select any employee name from listbox and press "EDIT" button, then i need to display the employee details for that particular employee what we selected in listbox. right now what i did is...
3
29320
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 where we can see more than one item and change the color during run time. Thanks.
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8905
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
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 we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.