Hi ,
I want to add a new item to combibox at runtime. Actually in my form i am having a textbox,combobox and a button. After entering item name in textbox and then clicking on button, the new item has to added to the combobox items list.

Thanks in advance

What problem are you having it with it?

If you're new to C#, then it's just :
combobox1.items.add(object);
To add 1 item.

I am same problam in .net i want add new item at run time helpe me

ComboBox.Items.Add(TextBox1.Text);

That should do it.

ComboBox.Items.Add(TextBox1.Text);

That should do it.

Sir this item add temptrarely,when i close my form thess item wel be delete i want parmanatle add,i hope you pick mt point.

Sir this item add temptrarely,when i close my form thess item wel be delete i want parmanatle add,i hope you pick mt point.

What are you trying to load from? If you're trying to load the values from a database or an XML file, then you can use Databinding to bind the combobox to a data source, where you've added all of the choices in advance.

If you're not doing that, I don't quite understand your question-- adding a value at runtime via code is going to do just that-- add the value at runtime. Unless you institute some kind of persistence via an XML file or some sort of data source, you can't persist the choices in a combo box past when a user closes the application.

brother i add the new item in combobox whitout any databas,as we add the item in desin time ok

You can't expect your code to do things you don't tell it to do. If you need to remember things, it will need to be saved to some form of media. The simplest form of this would be a textfile. Google reading/writing from textfiles in c#, use your knowledge of windows controls, and connect the dots!

i assume you are loading your combobox w/ data from a db, using ado.net. if so, then the way I would do this within your button click event...

1) query your db for a dataset that only contains the info you want to display in your cbox (ie one column).

2) add a row to your dataset from the user input. (ie. ds.tables[0].rows.add(variable))

3) update your ds (adapter.update(ds))

4) re-load your combobox (combobox.datasource = ds)

this is obviously not the complete code, but if you want to achieve your goal, this will do it...

I want Same But I Dont Want to Use any Object Like Textbox and all.
I want To write In Combobox.text to add New Item .

Will You Please Help me ?
I had Done but There Is Reapeting Items. Ex. I wrote "Apple" 1st time second time I m Selecting apple Then there Is two Times "Apple" in Combobox Items.
What Shoul I do ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.