Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to fetch name list in combobox but at the time of fetching i want to add select word in the combo before showing the name list.plz help me?
Posted

Try this:
C#
//After binding
comboBox1.Items.Insert(0, "Select");
comboBox1.SelectedIndex = 0;
 
Share this answer
 
v2
Comments
Member 9027346 26-Feb-14 0:20am    
it gives error-Item collection can not be modified when the database property is set.
Tom Marvolo Riddle 26-Feb-14 0:23am    
post your code .I'll check it and let you know
Member 9027346 26-Feb-14 0:28am    
cmbplant.DisplayMember = dt.Columns["PlantName"].ToString();
cmbplant.ValueMember = dt.Columns["PlantId"].ToString();
cmbplant.DataSource = dt;
cmbplant.Items.Insert(0, "Select");
cmbplant.SelectedIndex = 0;
Tom Marvolo Riddle 26-Feb-14 1:06am    
As the error says the database property is already set. you have to create a new row and add it or get it in the query
This would work for you :)
C#
ComboBox1.Items.Insert(0, "Select Items");
ComboBox1.SelectedIndex = 0;

-KR
 
Share this answer
 
Comments
King Fisher 26-Feb-14 0:25am    
solution 1==solution3
if you want need to add  "select" value,then you'll need to manually add  "select" item to your data source and set that as the default item.
 
Share this answer
 
Insert Method use to add element with specifying index

SQL
ComboBox1.Items.Insert(0, "Select Items");
ComboBox1.SelectedIndex = 0;
 
Share this answer
 
try and simplify this code

C#
ComboBox obj =  (ComboBox)comboBox1;
DataTable dt1 = (DataTable)obj.DataSource;
DataTable dt2=dt1.Copy();
dt1.Clear();
DataRow dr = dt1.NewRow();
dr[1] = "select word";
dr[0] = 0;
dt1.Rows.Add(dr);
dt1.Merge(dt2);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900