473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sorting a combobox

Hello
I use the following code to populate a combobox

Me.cbxPeerReview.DropDownStyle = ComboBoxStyle.DropDownLis
With cbxPeerRevie
.DataSource = dtEm
.DisplayMember = "STR_NAME_F
.ValueMember = "ID_USER
End Wit
Me.cbxPeerReview.DroppedDown = Tru
Me.cbxPeerReview.SelectedIndex = -

I want to sort to combobox by the "STR_NAME_F", but if I add the .sorted = true line, I get the following error

An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dl
Additional information: Cannot sort a ComboBox that has a DataSource set. Sort the data using the underlying data model

How do I sort the data using the underlying data model?

Thanks
Amber
Nov 20 '05 #1
2 4381
I guess dtEmp is a DataTable...all you have to do is sort the dataTable before you set it as the datasource
Nov 20 '05 #2
Create a DataView based on the table...

Dim myView as DataView = dtEmp.DefaultView
Then you can sort on any field you want. From there, just substitute
..DataSource = dtEmp with .DataSource = myView

HTH,

Bill

www.devbuzz.com
www.knowdotnet.com

"amber" <an*******@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
Hello,
I use the following code to populate a combobox:

Me.cbxPeerReview.DropDownStyle = ComboBoxStyle.DropDownList
With cbxPeerReview
.DataSource = dtEmp
.DisplayMember = "STR_NAME_F"
.ValueMember = "ID_USER"
End With
Me.cbxPeerReview.DroppedDown = True
Me.cbxPeerReview.SelectedIndex = -1

I want to sort to combobox by the "STR_NAME_F", but if I add the .sorted = true line, I get the following error:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll Additional information: Cannot sort a ComboBox that has a DataSource set. Sort the data using the underlying data model.
How do I sort the data using the underlying data model??

Thanks!
Amber

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
3
by: Paul Fairless | last post by:
Customers table - contains Columns: CustID, Surname, Forename, TtlID Titles table - contains Columns: TtlID, Title TtlID is a Foreign Key in the Customers table. I have a Form frmCustomers...
2
by: Todd | last post by:
Hi. I want to sort the records on my form (using either a continuous form or a datasheet) by the unbound "description" column in a combo box on the form (or in the datasheet.) Here's a rough...
1
by: aquanova | last post by:
I'm working on Microsoft Access. I have a form which views the record of one table. Inside the form, there are several columns. Now I want to sort the records with using combobox. Eg. if the value of...
4
by: Michal | last post by:
Hello, Question showed on short example: I got Table with personal information with field 'Name' If in Query based on that Table in 'Criteria' field for 'Name' I put something in '' brackets f.e....
3
by: DeWittds | last post by:
I have a combo box that I can not get to sort correctly. I fill the combobox with a customer id and name ( combined) have set the combobox.sorted = true I saw one Idea here about turning the...
3
by: Jimmy | last post by:
Is there a way to sort/group a report based on the second column of a combo box, i.e. the text associated with the primary key number?
6
by: carlos123 | last post by:
I have a programming assignement that i have been working on for quite some time now. I need your guys' help. My assignement is to great a table with data in it. and it will have a combobox and 2...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.