VB.net... MS Access data files

Got 2 Comboboxes. Both are bound to a DataSet. One lists a groups of
numbers. The other associated names.

The current method is to list the Combobox with numbers (which they are in
numeric order in the Access data file).

What I want to accomplish is to give a user the method to toggle the
associated names to be sorted or not (not at startup).

When I try to Sort the Combobox of associated names (combobox2) I get the
error:

Can't sort a ComboBox that has a DataSource set. Sort the data using the
underlying data model.

How can this be accomplished?

Many thanks

Ralph

Re: How to Sort ComboBox that has a DataSource? by Paul

Paul
Wed Oct 29 07:30:30 CST 2003

On Wed, 29 Oct 2003 00:58:01 GMT, RamChip <Notme@notanaddress.xxx> wrote:

¤ VB.net... MS Access data files
¤
¤ Got 2 Comboboxes. Both are bound to a DataSet. One lists a groups of
¤ numbers. The other associated names.
¤
¤ The current method is to list the Combobox with numbers (which they are in
¤ numeric order in the Access data file).
¤
¤ What I want to accomplish is to give a user the method to toggle the
¤ associated names to be sorted or not (not at startup).
¤
¤ When I try to Sort the Combobox of associated names (combobox2) I get the
¤ error:
¤
¤ Can't sort a ComboBox that has a DataSource set. Sort the data using the
¤ underlying data model.
¤
¤ How can this be accomplished?

What it is saying is that you should perform your sort when you query the database so that your
associated names are in order.


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)

Re: How to Sort ComboBox that has a DataSource? by Mr

Mr
Wed Oct 29 09:33:47 CST 2003

With Deft Fingers, Paul Clement <UseAdddressAtEndofMessage@swspectrum.com>
wrote:

>What it is saying is that you should perform your sort when you query the database so that your
>associated names are in order.

So in order for me to have both an option to view a sorted number Combobox and
a names combobox I'll need to have 2 datasets? Oh well... okay. Kinda knew I
could do that... but hoped that there was a way to do it via code.

Thanks!

Re: How to Sort ComboBox that has a DataSource? by Paul

Paul
Wed Oct 29 13:35:07 CST 2003

On Wed, 29 Oct 2003 15:33:47 GMT, Mr. B <User@NoWhere.Com> wrote:

¤ With Deft Fingers, Paul Clement <UseAdddressAtEndofMessage@swspectrum.com>
¤ wrote:
¤
¤ >What it is saying is that you should perform your sort when you query the database so that your
¤ >associated names are in order.
¤
¤ So in order for me to have both an option to view a sorted number Combobox and
¤ a names combobox I'll need to have 2 datasets? Oh well... okay. Kinda knew I
¤ could do that... but hoped that there was a way to do it via code.

The only other way I can think of is to use an Array as the DataSource which would of course require
the additional step of getting your data into the array.


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)

Re: How to Sort ComboBox that has a DataSource? by HussAb

HussAb
Wed Oct 29 18:49:09 CST 2003

Actually you could accomplish this if you create 2 DataView objects from the DataTable and sort each one as you like then bind each DataView object to the ComboBox
desired. The following demonstrates how to do it:

Dim da1 As SqlDataAdapter = New SqlDataAdapter("select * from Customers", cn)
da1.Fill(ds, "customers")

Dim dv1 As DataView = New DataView(ds.Tables("Customers"))
Dim dv2 As DataView = New DataView(ds.Tables("Customers"))

dv1.Sort = "CustomerID"
ComboBox1.DataSource = dv1
ComboBox1.DisplayMember = "CustomerID"

dv2.Sort = "CompanyName"
ComboBox2.DataSource = dv2
ComboBox2.DisplayMember = "CompanyName"

I hope this helps!


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.



Re: How to Sort ComboBox that has a DataSource? by Mr

Mr
Wed Oct 29 20:54:44 CST 2003

On Thu, 30 Oct 2003 00:49:09 GMT, in microsoft.public.dotnet.framework.adonet
you wrote:

>Actually you could accomplish this if you create 2 DataView objects from the DataTable and sort each one as you like then bind each DataView object to the ComboBox
>desired. The following demonstrates how to do it:

>I hope this helps!

Thanks. Yes it does. Actually I was (eventually) going to just create
another DataAdapter (for sorting via names). Then toggle between my original
DataAdapter (which is the default sort by numbers) and the 2nd DA.

But I'll try your method (always looking for better coding methods).

Thanks!