By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

To add the string in the text box to a dropdown list or Listbox

P: 53
Hi All,

I have one more question in my project, Last time the reply I got really helped me a lot . This is the project in WinForm(C#). I want to copy the text in the text box to a dropdownlist or listbox (or any other control) where I can keep adding the string which I enter in my text box everytime? Since I am new to .NET can someone help me with this? Thanks a lot for the help.
Feb 6 '09 #1
Share this Question
Share on Google+
1 Reply


vekipeki
Expert 100+
P: 229
Where are you stuck exactly?

If you know how to add items to any collection programmatically, then you can easily apply that to any similar control.

Every control that behaves as a "list" (ComboBox, ListBox), usually has a property which implements the IList interface.

If a class implements IList, then it must implement its methods - like Add, Remove, Contains etc. (check ths MSDN documentation for a complete list: IList interface members).

For example, ComboBox.Items is a property which implements the mentioned IList interface. This means that we can add items to that property, using the Add method. Check MSDN for an example: ComboBox.Items.

Expand|Select|Wrap|Line Numbers
  1. myComboBox.Items.Add("some item");
  2. myComboBox.Items.Add("some other item");
If you can add a constant string to your combo box, then you can also add any property which is a string:

Expand|Select|Wrap|Line Numbers
  1. string itemToAdd = myTextBox.Text;
  2. myComboBox.Items.Add(itemToAdd);
Feb 6 '09 #2

Post your reply

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