Tom
Tom

Reputation: 4577

Problems properly configuring VB.NET combobox

I need to put a combobox on a form that displays a list of customers.

Each customer has a customer number and customer name.

I figured out that VB.NET doesn't have multi-column combo boxes so to get around that I was going to query the data and put a tab between the customer number and name for the display members and have the value member be the customer number:

SELECT CustomerNumber AS ValueMember,
CustomerNumber + CHAR(9) + CustomerName AS DisplayMember
FROM Customers
ORDER BY CustomerNumber

This only works partially in that in the selected area of the combobox, the tab between the number and name shows but when you drop-down the combobox, the tab is not preserved.

Why there is no multi-column combobox native to VB.NET annoys me but that's whole other topic.

Does anyone have any ideas for a solution to this problem that doesn't involve getting a third-party control?

Thanks.

Upvotes: 0

Views: 487

Answers (1)

George Johnston
George Johnston

Reputation: 32258

If the drop down doesn't support the tab character, just replace your tab character with white space. e.g.

SELECT CustomerNumber AS ValueMember, 
CustomerNumber + '   ' + CustomerName AS DisplayMember 
FROM Customers 
ORDER BY CustomerNumber 

Am I missing something? Are you using the tab character for anything else besides formatting the displayed data? Otherwise, 4 white spaces should achieve the same effect.

Upvotes: 1

Related Questions