Binding Lookup-ComboBox

Aug 8 2008 5:47 AM
Hi all,

I want to use a ComboBox to let user to fill a lookup field, but no idea how to do that.

I have two tables, PO and Buyer. In PO table, it has a field buyer_id to specify which the buyer involves this PO. Now in PO maintenance form it has a ComboBox "cbBuyer" which is for accessing buyer_id of PO table.

Buyer:
- id field
- name field

PO table:
- id field
- buyer_id field

class PO_Form
{
            ...
            cbBuyer.DisplayMember = "name";
            cbBuyer.ValueMember = "id";
            cbBuyer.DataSource = BuyerDAO.QueryAll().ToArray();
            cbBuyer.DataBindings.Add("Text", po, "buyer_id");         // This code has bug !!!
            ...
}

When I run the application, cbBuyer ComboBox drop down item has all Buyers name properly, but when user select one of the ComboBox item and leave the ComboBox, the value is disappeared.

How can I bind it up properly?

Thank you very much.

Best regards,
Diviner.

Answers (1)