PC Review


Reply
Thread Tools Rate Thread

How to Sort ComboBox that has a DataSource?

 
 
RamChip
Guest
Posts: n/a
 
      29th Oct 2003
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
 
Reply With Quote
 
 
 
 
Paul Clement
Guest
Posts: n/a
 
      29th Oct 2003
On Wed, 29 Oct 2003 00:58:01 GMT, RamChip <(E-Mail Removed)> 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 ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
 
 
 
Mr. B
Guest
Posts: n/a
 
      29th Oct 2003
With Deft Fingers, Paul Clement <(E-Mail Removed)>
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!
 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      29th Oct 2003
On Wed, 29 Oct 2003 15:33:47 GMT, Mr. B <(E-Mail Removed)> wrote:

With Deft Fingers, Paul Clement <(E-Mail Removed)>
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 ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
Hussein Abuthuraya[MSFT]
Guest
Posts: n/a
 
      30th Oct 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.


 
Reply With Quote
 
Mr. B
Guest
Posts: n/a
 
      30th Oct 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!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ensuring Combobox has Value entered if another ComboBox has aspecific value Gareth Hardman Microsoft Excel Programming 3 9th May 2012 11:05 AM
Refined Sort - Sort within a Sort Bishop Microsoft Excel Programming 0 7th Apr 2009 09:00 PM
Sort, and then sort from the first sort =?Utf-8?B?S0I=?= Microsoft Access 9 9th Jun 2006 04:07 PM
How Do I Load A ComboBox RowSource From The Results Of Another ComboBox Minitman Microsoft Excel Programming 3 26th Oct 2004 07:58 PM
Populating combobox from another combobox David Goodall Microsoft Excel Programming 1 12th Sep 2004 03:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:52 AM.