Reputation: 45
I have a combobox that is populated by a column in a MYSQL table.
When an item in this combobox is clicked on it is supposed to show the corresponding record in textboxes.
It doesn't do that. Instead it shows the previous record to the one I selected.
I don't have enough rep to post an images here but if you need a better understanding, here is the image link;
http://www.tiikoni.com/tis/view/?id=be86310
(no adds or popups. just the image)
This is the code
private void Domain_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string sqlcon = "datasource = localhost; port = 3306; username = root; password = Avalisque";
string query = "select * from users.stmp where domain = '" + this.Domain.Text + "' ;";
MySqlConnection con = new MySqlConnection(sqlcon);
MySqlCommand cmd = new MySqlCommand(query, con);
MySqlDataReader rdr;
try
{
con.Open();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string semail = rdr.GetInt32("email_ID").ToString();
string sserver = rdr.GetString("server");
string sport = rdr.GetString("port");
string ssecurity = rdr.GetString("security");
Domain_ID.Text = semail;
STMP.Text = sserver;
port.Text = sport;
security.Text = ssecurity;
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Funny / fustrating part, this code works perfectly in a normal textbox. Type in "Gmail", and gmail setting pop up the moment you finish pressing 'l'...
Any Ideas?
Upvotes: 1
Views: 79
Reputation: 786
Basically: You do not want to do things this way in WPF, use MVVM instead...
If you must, i suggest you get the selected item either from sender
or even better, the AddedItems
property of e
- i have no idea what this.Domain.Text
points to, but it obviously changes after the event is fired. Though as i said you really want to use MVVM as much as possible when working with WPF, so using the pattern you'd simply have a CurrentDomain
property and bind the ComboBox
's SelectedItem
and all the controls displaying the information to it.
Upvotes: 2