473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Listbox to Combo Box

Hello All,

I have a tabcontrol control , In the tabpage1 I have listbox with some items, and in the tabpage2 I have a combo box, How to transfer the items(all the items) from the Listbox in tabpage1 to Combo box in tabpage2 without User selecting the items in the listbox.

The below code transfers only one selected item, but I want to transfer all the items....

private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Add(listBox1.SelectedItem);

}

Thank you all....
Feb 11 '09 #1
8 8096
I have a tabcontrol , In tabpage1 I have a listbox with few Items, In tabpage2
I have ComboBox, I want to copy all the Items in the listbox to combobox without user selecting the Item in the Listbox.

I am trying the following code:


private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Add(listBox1.SelectedItem);
}

This works when user selects an item in the listbox . But I want to transfer all the items in the listbox to combobox without selecting the items.

Thank you all....
Feb 11 '09 #2
tlhintoq
3,525 Expert 2GB
PageTwoCombobox.items = PageOneListbox.items;
Feb 11 '09 #3
I want to copy all the items in the listbox to mutlitple combo box, The solution given is not working...its tabpage1 not recognised...........I want to copy to mutlitple combo box
Feb 11 '09 #4
tlhintoq
3,525 Expert 2GB
The names of the controls are not dependant on the tab pages.
You should be able to copy directly from the item collection of one control to the item collection of another with no reference of which tab page they are on.
So don't try to reference them by pages, just by control names.
Feb 11 '09 #5
It says Listbox1 is readonly..

This is how I tried:
listBox1.Items = comboBox1.Items;
Errors:

1. indexer 'System.Windows.Forms.ListBox.Items' cannot be assigned to -- it is read only
2.Cannot implicitly convert type 'System.Windows.Forms.ComboBox.ObjectCollection' to 'System.Windows.Forms.ListBox.ObjectCollection'

and I want to copy from a single Listbox1 to mutliptle Combobox...
Feb 11 '09 #6
tlhintoq
3,525 Expert 2GB
Please don't think me rude when I ask, "Have you tried a little experimenting?"
Asking for the answers to specific needs may get you answers.
A little effort and experimentation will get you knowledge and understanding.

1. indexer 'System.Windows.Forms.ListBox.Items' cannot be assigned to -- it is read only
Since you are trying to read from the ListBox this shouldn't be a problem or even come up. Read only is fine if you are only reading from it to place those items into a ComboBox.

Try this... Loop through the items of the Listbox (your source) and use the .Add method of the ComboBox (your destination)

Expand|Select|Wrap|Line Numbers
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             for (int nIndex = 0; nIndex < listBox1.Items.Count; nIndex++)
  4.             {
  5.                 string bob = listBox1.Items[nIndex] as string;
  6.                 comboBox1.Items.Add(bob);
  7.             }
  8.         }
  9.  
Feb 11 '09 #7
tlhintoq
3,525 Expert 2GB
Please don't double post your questions.
http://bytes.com/topic/c-sharp/answe...tbox-combo-box
Feb 11 '09 #8
Oh Sorry...I thought the 1st time when I posted the question it didn't go through..I am really sorry for posting it twice...
Feb 12 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Scott | last post by:
I have an ASP page which show's a Drop-Down Combo box, and a ListBox. My Combo Box is populated from a SQL Select Statement which shows User Groups. I want to populate my Listbox with all the...
7
by: Colleyville Alan | last post by:
I have an app in which users are displayed a list of mutual fund from which they can choose. There is a listbox embedded in a two-tabbed notebook control. When the form is initally opened, the...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
1
by: dburns | last post by:
I have an unbound ListBox and an unbound ComboBox on the same form. I have them both set up to display the values from the same field in the same table. The ListBox displays the correct values; the...
0
by: David J | last post by:
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem...
7
by: technocraze | last post by:
Hi guys, I encountered this error while using the AfterUpdate event for my listbox. Error: Update or CancelUpdate without using AddNew or Edit. What i wanted to achieve is just to display the...
14
by: rdade22 | last post by:
I have a combo box (cboStore) and a listbox (Qlist) both are unbound to a form call frmFAQ. What I want is to be a able to select a Subject from the combo box and have the results show up in the...
3
by: deejayquai | last post by:
Hello Simple one this I guess, but I'm quite stuck at the moment. I would like to update the records displayed in my listbox (lstStudents) using criteria selected from my combo (cboForm) in a...
20
by: exipnakias | last post by:
Hello Guys. In a form I created a listbox which looks up the values of a table. I want: 1) ..to create a query where a parameter will be needed in order to be loaded. But I do not want to...
9
by: weirdguy | last post by:
Hello, Just for anyone information, there is a similar title "Search in Listbox" but it is via Combo Box. In case, anyone need it, I put a link to here. Please let me know if I break any rules...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.