Using DataTable.Select in ComboBox

  • Thread starter Thread starter Gene Hubert
  • Start date Start date
G

Gene Hubert

I'm looking at using the result of DataTable.Select as the DataSource
for a ComboBox. Is there an easy way to do this with a minimum of
code. I tried to bludgeon it into submission by writing:
myComboBox.DataSource = myDataTable.Select
and got appropriately vulgar results.

I know I could loop through the array of DataRows and add them to
another DataTable and then use that as the DataSource for a ComboBox.
If I have to do that much coding I'd probably look into using a
DataView instead.

Thanks for any assistance.
Gene H
 
Hi Gene,

The easiest way I can think of - there may well be better - is to assign a
datarow array the .select rows; then loop through the array and add the row
column you need.

I tried your approach, and, yes, your definition of 'vulgar' was
appropriate!

HTH,

Bernie
 
Gene,
If you are setting DataSource, I would recommend using a DataView instead.
myComboBox.DataSource = New DataView(myDataTable, ...)

David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press
covers using a DataView verses using the DataTable.Select methods and when
you would or would not use each.

David's book is both a good tutorial on ADO.NET plus a good desk reference
once you know ADO.NET!

Hope this helps
Jay
 
Hi Gene,

In addition to Jay B.

I also suggest to use the dataview.
\\\
dim dv as new dataview(mydataset.tables("mytable")
dv.rowfilter = "mysortitem < 100"
dv.sort = "mysortitem"
mycombobox.datasource = dv
mycombobox.displaymember = "xx"
///
This give you with a miniumum of code the maximum results in my idea.

Cor
 
Thanks much to everyone. I'm definitely looking for miniumum code and
maximum results. It seems that an array of datarows requires more
coding that I prefer to make it useful to a ComboBox. I'll be going
with a dataview.

Gene H.
 
Back
Top