Vb.net[2008] Combobox Header row when populated from datasource

  • Thread starter Thread starter Rob W
  • Start date Start date
R

Rob W

Greetings,

Is it possible to create a header row for a combo box which is populated
from a datasource?

For example a header row similar to '--Please choose a value--' then the
other values would be populated from the datasource.

I've looked at the combobox properties and experimented with the items.add
code statements which are rejected due to the combobox having a datasource.
I also don't have a clue how to create a pseudo row in SQL to create a
header row.

Any tips or advice would be appreciated, thanks

Rob
 
Often times, it is easier to adjust your data set prior to binding than it
is to add additional members to the bound control. In what you describe, you
can add it to the SQL statement or add to the data set prior to binding
(note I am saying data set and not DataSet, as your particular
implementation may be LINQ or EF).

As for creating a pseudo row in SQL, it is like this:

SELECT o as foo, 'Choose an item' as bar
UNION ALL
SELECT foo, bar
FROM Table1
Order by foo

The 0 will populate the choose at the top. You can then do whatever you need
to stop 0 from submitting, including add validation that the combo box != 0.
Hope this helps!

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

********************************************************
| Think outside the box! |
********************************************************
 
Back
Top