Click here to Skip to main content
15,886,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
The combo box is populated but it seems that the selected index does not work,
because the combo box does not show "<-- Select a Status -->" in display.
Do you know why please?
Thanks
C#
private void PopulateTaskStatus()
        {
            DataTable dtTaskStatus = TaskStatusGet();

            DataRow newRow = dtTaskStatus.NewRow();

            dtTaskStatus.Columns["Status"].MaxLength = 50;
            newRow["Status"] = "<-- Select a Status -->";

            dtTaskStatus.Rows.InsertAt(newRow, 0);

            cboStatus.DataSource = null;

            cboStatus.Items.Clear();
            cboStatus.DisplayMember = "Status";
            cboStatus.DataSource = dtTaskStatus;

            cboStatus.SelectedIndex = 0;
        }
Posted
Comments
manognya kota 24-Jan-12 7:37am    
can you see others elements in your combobox ? also are you seeing the <-- Select a Status --> as a last option in the combo box?

Hello,

you can try this find by text and find by value

cboStatus.Items.FindByText("Status").Selected = true; OR
cboStatus.Items.FindByValue("Status").Selected = true;
 
Share this answer
 
Can you see what I am doing wrong in my sample code?
This works fine for other forms I use it in.
Thanks
 
Share this answer
 
yes, I can see all items in the combo box.
The first item is <-- select an item -->

As you can see in th ecode I sent earlier, I do not see why cboStatus.SelectedIndex = 0; does not show this item as the selected item in combobox.
Do you see why?
This method works in other forms with other table data.
Thanks
 
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