473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listbox to Combo Box

53 New Member
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 8106
sbandalli
53 New Member
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 Recognized Expert Specialist
PageTwoCombobox.items = PageOneListbox.items;
Feb 11 '09 #3
sbandalli
53 New Member
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 Recognized Expert Specialist
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
sbandalli
53 New Member
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 Recognized Expert Specialist
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 Recognized Expert Specialist
Please don't double post your questions.
http://bytes.com/topic/c-sharp/answe...tbox-combo-box
Feb 11 '09 #8
sbandalli
53 New Member
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
3024
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
2001
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
3590
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
1611
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
2633
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
4067
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
12304
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
2460
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
5185
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
10657
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
7264
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
7166
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
7543
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...
1
7106
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
7534
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...
1
5094
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...
0
4749
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
3236
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...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.