Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please help me

I have five values in combobox

Example:

Chennai
Bangalore
Trivandrum
India
US
when the form is display

i want to display 4th value (India) is selected by default

what is the code
Posted
Comments
[no name] 19-Jul-13 6:13am    
Have you tried anything? Anything at all? Did you try myCombobox.Selectedindex = 3?
hebsiboy 19-Jul-13 6:19am    
this combobox is inside the datagrid so is this work or not?
[no name] 19-Jul-13 7:35am    
So, in other words, you have not tried anything and are wasting all of our time.
Naz_Firdouse 19-Jul-13 6:25am    
specify your requirement clearly...
Mention in your question that your combobox is within the datagrid
hebsiboy 19-Jul-13 6:33am    
In dataGridView Has one combobox that having 5 values
when the page is loaded i want to select 4th values from combobox
by default

try this :

combobx1.Text = "India"

but if you have a datagridview it's different :
to create it by code :

C#
string[] str = {"Chennai","Bangalore","Trivandrum","India","US"};
 DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
                cmb.HeaderText = "Headertext";
                cmb.Name = "name";
                cmb.MaxDropDownItems =str.Count() ;
                foreach (String o in str)
                {
                   cmb.Items.Add(o);
                }
                dataGridView.Columns.Add(cmb);


then to change the text you should use :

C#
for (int i = 0; i < dataGridView.Rows.Count - 1; i++)
             {
                             dataGridView.Rows[i].Cells[where the combobx located].Value = "India";
             }
 
Share this answer
 
v2
Try comboBoxLocation.SelectedIndex=3
 
Share this answer
 
Write this code on your Form load event

C#
combobox1.SelectedIndex=combobox1.FindStringExact("India");


Thanks & Regard
Sham :)
 
Share this answer
 
try this

comboBox1.SelectedText ="India";
 
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