Click here to Skip to main content
15,902,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends ,

I have Asssigned datsource to combobox and I want to display default item like "Select an Item" in combobox starting item.now combobox ,it displays data directly.whatever i assigned datasource,but i want to give starting item as --SELECT-- in combobox

If anyone can help on how to achieve this, it would be appreciated.

thanks.
Posted
Updated 26-Jul-10 23:40pm
v3
Comments
DaveAuld 27-Jul-10 4:04am    
"give solution" is not a very nice way to ask for help, i have edited your question to make it a bit more polite.
babuatcha 27-Jul-10 5:50am    
thank u very much.

where you are binding the datasource with the comboBox there you just insert a new Item in DataSource of comboBox .. i am assuming that you have binded a DataTable as "dt" to the ComboBox...
so

DataRow dr = dt.NewRow();/* 'dt' is the DataSource of ComboxBox as DataTable*/
dr["columnName"]="---Select---";
dt.Rows.InsertAt(dr,0);
comboBox1.SelectedIndex=0;


this have to be after the binding of DataSource to ComboBox..
my previous answer was totally wrong....
you cant modify the Item Collection of a ComboBox when that ComboBox is binded to some DataSource...
if you need to modify the Items of that ComboBox then you must modify the DataSource of that ComboBox...
 
Share this answer
 
v3
Comments
babuatcha 27-Jul-10 5:48am    
cmbScoohlName.Items.Insert(0, "--Select School--");
cmbScoohlName.SelectedIndex = 0;

cmbScoohlName.DisplayMember = "SNAME";
cmbScoohlName.ValueMember = "ID";

cmbScoohlName.DataSource = dataset.Tables[0];
but it's not coming.plz give clear idea on this
babuatcha 27-Jul-10 5:48am    
Reason for my vote of 1
i problem solved 50%
babuatcha 27-Jul-10 5:56am    
Reason for my vote of 1
sdfds
koool.kabeer 27-Jul-10 6:01am    
you are Binding the Data from database or any other source to combobox ...
after that you can see the Items in the Combox.... Here all the Items are ready for use in Combox .. now You want to add your new Item as "Select School" so just Insert it in the location(index) and set the SelectedIndex.
koool.kabeer 27-Jul-10 6:02am    
and my lines of code must be after the line of


cmbScoohlName.DataSource = dataset.Tables[0];

not before it
What have you tried so far? Post some code here and maybe someone can help you.
 
Share this answer
 
mbScoohlName.Items.Insert(0, "--Select School--"); cmbScoohlName.SelectedIndex = 0; cmbScoohlName.DisplayMember = "SNAME"; cmbScoohlName.ValueMember = "ID"; cmbScoohlName.DataSource = dataset.Tables[0];
 
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