J
JTC^..^
When i attempt to bind to the "Text" and "Value" property of a combobox
on a windows form the value is reset when I leave the combobox. The
comboboxes contain the correct Text and Values. I know this as the Value
property binds correctly on it own. It is only when I bind the "Text"
and "Value" that the issue occurs.
The following sample code includes my custom classes and the Form Clode.
I have several comboboxes and customer classes used as properties in the
Product class.
public class Product
{
private Customer _cust;
public Customer Customer
{
get{return _cust;}
set{_cust = value;}
}
....
}
public class ProductList : List<Product>
{
}
public class Customer
{
private int _id;
public int Id
{
get{return _id;}
set{_id = value;}
}
private string _name;
public string Name
{
get{return _name;}
set{_name= value;}
}
....
}
public class CustomerList : List<Customer>
{
// code to get list of customers
}
public class Form1 : Form
{
private CustomerList _custList;
private ProductList _prodList;
...
public void Form1()
{
InitializeComponents();
this.cboCustomers.DataSource = _custList;
this.cboCustomers.DisplayMember = "Name";
this.cboCustomers.ValueMember = "Id";
_prodList = new ProductList;
_prodList.Add(new Product());
BindingManagerBase bm = this.BindingContext[_prodList];
bm.Position = 0;
this.cboCustomers.DataBindings.Add("Text", _prodList,
"Customer.Name");
this.cboCustomers.DataBindings.Add("Value", _prodList,
"Customer.Id");
}
}
Thanks...
on a windows form the value is reset when I leave the combobox. The
comboboxes contain the correct Text and Values. I know this as the Value
property binds correctly on it own. It is only when I bind the "Text"
and "Value" that the issue occurs.
The following sample code includes my custom classes and the Form Clode.
I have several comboboxes and customer classes used as properties in the
Product class.
public class Product
{
private Customer _cust;
public Customer Customer
{
get{return _cust;}
set{_cust = value;}
}
....
}
public class ProductList : List<Product>
{
}
public class Customer
{
private int _id;
public int Id
{
get{return _id;}
set{_id = value;}
}
private string _name;
public string Name
{
get{return _name;}
set{_name= value;}
}
....
}
public class CustomerList : List<Customer>
{
// code to get list of customers
}
public class Form1 : Form
{
private CustomerList _custList;
private ProductList _prodList;
...
public void Form1()
{
InitializeComponents();
this.cboCustomers.DataSource = _custList;
this.cboCustomers.DisplayMember = "Name";
this.cboCustomers.ValueMember = "Id";
_prodList = new ProductList;
_prodList.Add(new Product());
BindingManagerBase bm = this.BindingContext[_prodList];
bm.Position = 0;
this.cboCustomers.DataBindings.Add("Text", _prodList,
"Customer.Name");
this.cboCustomers.DataBindings.Add("Value", _prodList,
"Customer.Id");
}
}
Thanks...