Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a combo box where i want to put other at the last while retrieving it through database and select at the top of combo box and all other entries in between them in ascending order of alphabet pls tell me how to do this
Posted
Comments
BillWoodruff 21-Feb-14 2:20am    
Is this Windows Forms ? Do you have binding working where you are able to display database items in the ComboBox now ?
ank170989 21-Feb-14 2:30am    
yes this a window form with binding from database
Tom Marvolo Riddle 21-Feb-14 2:33am    
answer updated try it and let me know

use this it may help you.
comboBox1.Items.Insert(0, "Select");
comboBox1.SelectedIndex = 0;
 
Share this answer
 
v2
Get count from database and assign it to integer

Try this after binding:
C#
SqlCommand cmd = new SqlCommand("select count(*) from table", con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
    count = int.Parse(dr[0].ToString());
    dr.Close();
}
comboBox1.Items.Insert(00, "select");
comboBox1.Items.Insert(count+1, "other");
comboBox1.SelectedIndex = 0;
 
Share this answer
 
v2
Comments
ank170989 21-Feb-14 5:05am    
i am getting following error
InvalidArgument=Value of '5' is not valid for 'index'.
Parameter name: index
Tom Marvolo Riddle 21-Feb-14 5:08am    
post your code here.I'll check it and let you know

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