Databinding Null (VB Nothing) values

G

Guest

I have a listbox who's dataSource is an array of Classes of the type
Discount. and this listbox is bound to a Customer's Discount property.

Customer c = CustomerFactory.GetInstance(2342);
Dicsount[] d = DiscountFactory.GetAll();
ListBox1.DataSource=d;
ListBox1.DisplayMember="Description";
Listbox1.DataBindings.Add("SelectedItem",c,"Discount");

This works beautifully. However, for some customers there will be no
discount. In this case, I would need a "No Discount" option in my listbox
whose value is null so that the customer.Discount property is set to null.
Can this be done somehow? Can you add an item to a listbox os combobox that
sets a databound property to null?

I know that I could ass a Discount instance to the array whose description
is "No Discount." However, that's kind of sloppy. There is a lot of logic in
my app that checks for things like "if(myCustomer.Discount==null)" and
checking for "if(myCustomer.Discount.Description=="No Discount")" is
effectively hard-coding database values into your app (baaaaad idea)

So, any thought? anyone?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top