Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My code below work and give result in load form and not result in selectedchangedevent combobox why

Status
Not open for further replies.

ahm1985

Programmer
Dec 6, 2012
138
EG
I have combobox i want to show data in selectedindex changed event but it not accept although this code retrieve data in load event of form

private void bind1()

{


con.Open();

da = new SqlDataAdapter("Select NationalityID,NationalityName from Nationality", con);

dt = new DataTable();

da.Fill(dt);


SqlConnection con = new SqlConnection("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "");// DataRow dr;


dr = dt.NewRow();


dr.ItemArray = new object[] { 0, "---Select Nationality---" };


dt.Rows.InsertAt(dr, 0);

comboBox2.DisplayMember = "NationalityName";

comboBox2.ValueMember = "NationalityID";

comboBox2.DataSource = dt;

comboBox2.Refresh();

con.Close();

}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

{

bind1();

}

this code above work fine and retrieve data in combobox by load event but i need to work in selected index changed event combobox

Why not retrieve data in selected index changed event of combobox
I work in windows application c#
and how i do that
 
Didn't you forget to call databind>

e.g. after

comboBox2.DataSource = dt;
call..
comboBox2.DataBind();
 
Sorry forget the last answer. I think that isn't necessary in winforms, just webforms.
Its been a long time since I have worked in a winforms app..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top