×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

Didn't you forget to call databind>

e.g. after

comboBox2.DataSource = dt;
call..
comboBox2.DataBind();

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

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..

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close