Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

IN Asp.net i used to set by default text for a year dropdown is folloing....
its work well..
C#
ddlFiscalYear.Items.Add("--Select Year--");
ddlFiscalYear.Items.FindByText("--Select Year--").Value ="0";
ddlFiscalYear.SelectedIndex = ddlFiscalYear.Items.Count - 1;

But i want the same functionality in windows applications..
In the windows i can't find "FindByText" Property,
How i cant get the same functionality in windows...

If u know help me.....

i am binding comboBox suing DataBase like following

C#
ds= ObjUtl.FillDropdownlist("Mt_GetPostName_For_DOBCriteria");
           cmbPostName.DataSource = ds.Tables[0];
           cmbPostName.DisplayMember = "Name";
           cmbPostName.ValueMember = "Id";


ComboBox binds successfully, and by default shows the first item in comboBox but i want first item is
-- Select Post -- which is added programatically by me.
i wrote the following code for that but didn't get the proper output

SQL
cmbPostName.SelectedText = "--Select PostName--";
            cmbPostName.SelectedIndex = -1;



will u help me to get my desired output........






Thanks & Regards
Honey 4 U........
Posted
Updated 5-Aug-11 3:08am
v4

cmbPostName.Items.Insert(0, "--Select PostName--"));
cmbPostName.SelectedIndex = 0;


or

DataRow row = ds.Tables[0].NewRow();
row["Name"] = "--Select PostName--";
row["ID"] = -1;
ds.Tables[0].Rows.Insert(row, 0);
 
Share this answer
 
Comments
honey4bee 5-Aug-11 10:12am    
by adding ur code i am getting the following error

error : Items collection cannot be modified when the DataSource property is set
[no name] 5-Aug-11 10:23am    
You need to insert the row BEFORE data binding
honey4bee 6-Aug-11 5:10am    
thank u...
Hai...

I got the solution by using the following code.

DataRow dr = ds.Tables[0].NewRow();
dr["Name"] = "--Select Post--";
ds.Tables[0].Rows.InsertAt(dr, 0);
These code i have written before the Binding with database..

Thanks & Regards
Honey 4 U..
 
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