473,387 Members | 1,575 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,387 software developers and data experts.

How to add new item in Combobox..

Hi Friends... i error while i m adding new item "Create New" into Combobox which is already binded by one datasource using datatable with valuemember.

plz help me in solving how to add new item into combobox which already databinded by datatable.
Jul 25 '07 #1
7 2169
bharathreddy
111 100+
hai,

Best way is to add the value to the datatable itself and assign this datasource/table to the Combobox once again.

Thanks & Regs
Bharath Reddy VasiReddy.
Jul 25 '07 #2
dip_developer
648 Expert 512MB
Hi Friends... i error while i m adding new item "Create New" into Combobox which is already binded by one datasource using datatable with valuemember.

plz help me in solving how to add new item into combobox which already databinded by datatable.
If you try to add items to a ComboBox that was bound, an ArgumentException is thrown, saying that "Cannot modify the Items collection when the DataSource property is set".

First you do your adding of item to datatable then bind it as datasource.

no other way of doing this.
Jul 25 '07 #3
Thnx for reply....my problem is .. i binded combobox with datasource, displymember and valuemember using single table.... i want to display [create New] text with the binded data in same combobox....
Jul 25 '07 #4
prabunewindia
199 100+
hi friend,
u can create a new ListItem and insert at the first(index 0) position
example:
ListItem createNew = new ListItem("text", "value");
dropdownlist.Items.Insert(0, createNew);
Prabu


Thnx for reply....my problem is .. i binded combobox with datasource, displymember and valuemember using single table.... i want to display [create New] text with the binded data in same combobox....
Jul 25 '07 #5
Plater
7,872 Expert 4TB
I would suggest not binding the combo box directly.
Instead, collect your datasource (a datatable or dataset maybe?)
And then itterate through it adding them to the combobox.
Then you are free to add and remove more entries as you please.
Jul 25 '07 #6
hi everyone,

this is what i m using..code...plz read... with this i m inserting new text into the combobox which assigned by datasource, datamember and valuemember. here i m not getting value member to my new text.... i want to add this as new item not a new text...


public struct State
{
private string _shortName, _longName;

public State(string longName, string shortName)
{
this._shortName = shortName;
this._longName = longName;
}

public string ShortName { get { return _shortName; } }
public string LongName { get { return _longName; } }
}
public State[] States = new State[] {
new State("Create","0")

} ;


private void bind()
{
DataTable dataemp;
dataemp= obj.getempid();
COB_Employeeid.DataSource = dataemp;
COB_Employeeid.DisplayMember = "Employee_Name";
COB_Employeeid.ValueMember = "Employee_ID";
COB_Employeeid.DataBindings.Clear();
COB_Employeeid.DataBindings.Add("Text", States, "LongName");
}
Jul 25 '07 #7
any one thr who can solve above problem...
Jul 26 '07 #8

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

Similar topics

2
by: Phil | last post by:
My form uses a dataset containing two tables, a base table (Contact) and a lookup table (Insurer). My combobox is bound as follows: DataSource = datasetContact DisplayMember =...
2
by: Nate | last post by:
I have used the feedback on this issue to remedy my comboboxes showing the first item on the list when a new record is added to the binding context --- Me.BindingContext(dsOrders,...
4
by: Drum2001 | last post by:
I have a combobox that is populated from a button on the form. One pushes this button and the following happens: !! = Me.ItemName So the combobox no shows whatever was in Me.ItemName. Here...
2
by: Brett Romero | last post by:
After I remove all items from a combobox, the last selected item remains in the display area. I've tried: mycbox.SelectedText = string.Empty; and mycbox.refresh(); How do I clear the...
9
by: Franky | last post by:
I have a usercontrol that inherits from ComboBox I'd like to add the feature that the user can delete any item Best would be that he could right click an element and a messagebox would ask if...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
4
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, when starting run app, how to let user add item/edit item to comboBox on the Form, Thanks, Martin
7
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR ...
0
by: sony.m.2007 | last post by:
Hi, I'm creating a combox control in XAML(WPF) and loading the items from a table in sql server. There are four items in the combobox.I need to hide an item in the combobox and to show three...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.