I am trying to update a MySQL entry in WPF. So I have a list of Tenant names in a combobox and when you click on the Combobox I want to put the first and last name in the textbox. So I have an SelectionChanged event and I try to set a string to cboTenantName.Text which is actually the previous selection and not the current. Now, when I try to set a string to Object SelectedItem.ToString all I get is some description “MySqlWpf.AddRentPayment+TenantData”. Perhaps it’s because I am storing the TenantData in an observable Collection. In that case how should I access it?
ObservableCollection _TenantDataCollection = new ObservableCollection();
public ObservableCollection TenantDataCollection
{ get { return _TenantDataCollection; } }
public class TenantData
{
public string Tenant {get; set;}
}
You’re getting the instance of the TenantData as the ComboBox’s selected item. What you want to display is the “Tenant” property. Thus, you have to do something like “myTextBox.Text = (selectedItem as TenantData).Tenant”.