wpf question about listboxes and textboxes

wpf question about listboxes and textboxes

Postby ashlar64 » Mon 28 Jan 2008 15:41


Here is what I want to do. I have a MySQL database that I want to fill with a field called Names.

I have various TextBoxes on the form and I want them to be changed to the right record when I click on the corresponding one in the ListBox. I have managed to do this. However when I try to edit one of the TextBoxes on the form it doesn't pass the new change back into the database. (The textbox that has the name field (the same field thats in the listbox) does change when you alter it in the textBox.)
Here is the code:

namespace iGlimpse2
public partial class Window1

public Window1()
mySqlConnection1.UserId = userid1;
mySqlConnection1.Password = password1;
mySqlConnection1.Host = host1;
mySqlConnection1.Port = port1;
mySqlConnection1.Database = database1;
catch (MySqlException exception)
MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK);



private void OnInit(object sender, EventArgs e)

dataSet_Site_ID1.Site_ID.Active = true;
listBox_Site_ID.DataContext = h1.dataSet_Site_ID1;
listBox_Site_ID.SelectedIndex = 0;


private void TextBox_Site_Name_LostFocus(object sender, RoutedEventArgs e)
// this code doesn't work



Here are some code snippets for XAML code:

ItemsSource= "{Binding Path=Site_ID}"
ItemTemplate ="{StaticResource Template_Site_ID}" />

(I probably shouldn't be binding the TextBox to the listBox_Site_ID but if I didn't how would the TextBox know to which record I would be pointing? I also thought you could do all the things I want to do just in XAML code?

Thanks in advance!
Posts: 75
Joined: Thu 04 May 2006 18:56

Postby Alexey.mdr » Tue 29 Jan 2008 11:25

Please send me a small test project to reproduce the problem.
It is desirable to use 'test' schema objects, otherwise include the
definition of your own database objects.

Do not use third party components.
If it is impossible for you to create the test project, send us a piece of
your code where the error occurs.
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Return to dotConnect for MySQL