Problem in Combo Box Using Windows Application
i have Combo box which is bind from database. i want to show text value of Combo Box when my form is running. but still its not showing me i dont know why its always getting first value from database not showing text value of combo box.this is the function which is i called at form load.and when user change the value of combob box on that time should be change values of combo box or or in other text boxes not at form load. hope you understand what i want...
get_party_details()
{
try
{
ds = new DataSet();
ds = gBL.show_party_details_name();
cb_party_name.DataSource = ds.Tables[0];
cb_party_name.DisplayMember = "Party_Name";
}
catch (Exception)
{
}
thanks in Advance please help me urgent.

Kirtan PatelPosted Nov 12, 2009, 7:40 AM
friend, there was lil Mistake in my Code above just correct it like below one
Now it will work :)
private void get_party_details()
{
try
{
DataSet ds = new DataSet();
ds = gBL.show_party_details_name();
//Insert Row Here
DataRow r = ds.Tables[0].NewRow();
// here instead of r["party_name"] you can also use Index of Column
r["Party_Name"] = "Select Party Name";
ds.Tables[0].Rows.InsertAt(r, 0);
cb_party_name.DataSource = ds.Tables[0];
cb_party_name.DisplayMember = "Party_Name";
}
catch (Exception)
{
}if Still having Problem then look at below Example I have coded For you to Show how to do it :)
Download My Example
:)
Naeem KhanPosted Jan 23, 2010, 12:51 AM
thanks in advance
Naeem KhanPosted Nov 12, 2009, 7:39 AM
Kirtan PatelPosted Nov 12, 2009, 7:13 AM
if possible can you send me project Files ??? so that i can solve it in very few Time :)
just Upload Project File (Zip) at http://mediafire.com with database too :)
and Give me the link they provide you to download it :)
will resolve it very Quickly :)
Naeem KhanPosted Nov 12, 2009, 7:00 AM
Kirtan PatelPosted Nov 12, 2009, 6:46 AM
you can not Directly Add new item to Combo box that is Bound to Some Database items
but you need to insert One Extra Row in Ds.Table[0] Which Will Contain this "Select party Name" before Binding ds.Table[0] to Combo Box
Code like Below
private void get_party_details()
{
cb_party_name.Items.Add("Select Party Name");
try
{
DataSet ds = new DataSet();
ds = gBL.show_party_details_name();
//Insert Row Here
DataRow r = new DataRow();
// Here Instad of r[3] use the Index of Column "Party Name" according to your Database Table Structure
r[3] = "Select Party Name";
ds.Tables[0].Rows.InsertAt(r, 0);
//After Adding New Row Now you can bind and It Will Show "Select Party Name in Combobox :)
cb_party_name.DataSource = ds.Tables[0];
cb_party_name.DisplayMember = "Party_Name";
}
catch (Exception)
{
//MessageBox.Show("Error!: " + ex.Message.ToString() + ". Please contact PSR Computers for Support");
}
if my answer Helps you then Check "Do you like this answer check box " :)