473,396 Members | 2,033 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,396 software developers and data experts.

Comboxboxes and the sorted property

Discovered a fun one that I thought I should share, and hopefully catch
Microsoft's attention to update some documentation.

I'm a bit new to VB.NET, and was struggling with getting a combo box to
work. I was attempting to take advantage of the cool way to load a combo box
via a datasource, rather than the old VB6 way of adding selections.

First I tried an array of objects. I had some issues with that that I
suspect had a lot to do with not overloading ToString on the class so the
combo box would return the right thing for the displaymember item. But I had
also read some bugs around arrays and combo boxes, so I switched to a
disconnected dataset.

I had a heck of a time getting the combo box to load properly. I kept
getting either no data in the combo box, or it kept showing the phrase
"System.Data.DataRowView". I found out that you have to set the datasource
property first, before you set the datamember and the valuemember properties.

But the real kicker was that you can't use the datasource and get it to work
if the sorted property on the combo box is set to true. It appears that if
you set that property to true, then the combo box assumes you're going to do
things the old VB6 way and use the Add items method to the combo box. My
tipoff something was wrong that I'd watch the debugger, and right after the
statement like this:

cbTest.DataSource = dsInfo.Tables(0)

the value of cbTest.Datasource was "nothing", like the assignment didnt take.

In order to get things to work the way I wanted them to, I simply built a
dataview that sorted the table for me, and fed that to the combobox with the
sorted value off, and it finally worked. Three weeks later, of course.

Would someone from Microsoft confirm that you shouldn't use datasource in
combo and list boxes if you set the Sorted property to true in the form
designer? If that is the case, note that somewhere in the MSDN information
about the ListBox and the ComboBox classes!! It's not mentioned in the
MSPress books either (I have Programming Microsoft Visual Basic.Net, the 2003
version, ISBN 0-7356-2059-8)

Nov 21 '05 #1
3 1451
Hi
Actually this behavior that you are experiencing is the expected one. When
you try to set a combobox as sorted while it is connected to a data source
(the sort criteria e configured) this actually sort an exception
(ArgumentException) which is thrown under the condition (An attempt was
made to sort a ComboBox that is attached to a data source.) this is
actually documented on the MSDN page the of the sorted property on combobox
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscomboboxclasssortedtopic.as p . so what happens here
is that the binding is never done as the exception is raised .

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #2
Three things:

1) The exception is not being raised to the application level, or if it is,
its being handled internal to the libraries, at least in VB.NET 2003. I never
saw it. What I saw was an empty combo box. If you'd like, I can send a very
short code snippet in VB.NET that demonstrates this, but you should be able
to recreate it very easily.

2) I would strongly reccommend that you add a comment in the Remarks section
of the iDataSource page of the ComboBox and ListBox classes that states "do
not use the sorted property when using a data source". When I was trying to
solve this problem, I looked in that topic for something I was doing wrong.
It was a coincidence that I stumbled on the sorted property being the cause.

3) I would suggest that you modify the section in the Sorted property of the
class description to clearly state that this property is to be used only when
using the add method.

"Mohamoss" wrote:
Hi
Actually this behavior that you are experiencing is the expected one. When
you try to set a combobox as sorted while it is connected to a data source
(the sort criteria e configured) this actually sort an exception
(ArgumentException) which is thrown under the condition (An attempt was
made to sort a ComboBox that is attached to a data source.) this is
actually documented on the MSDN page the of the sorted property on combobox
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscomboboxclasssortedtopic.as p . so what happens here
is that the binding is never done as the exception is raised .

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #3
Thanks scott.
Nov 21 '05 #4

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

Similar topics

4
by: Robert Zurer | last post by:
Assuming that I have created a strongly typed collection and overridden the appropriate methods, i.e. this, Add, Insert etc., so that a sort order is maintained, it's still very possible for a...
4
by: Cybertof | last post by:
Hi ! I would like to make an array of structure (collection ?) that would behave like an advanced sorted list : a sorted list with one key but with multiple values (sorted lists are key/value...
10
by: Ryan Graham | last post by:
I totally bombed this question in an interview so I'm posting my answer here for comments and suggestions... perhaps (god help me) I'm just not that bright, but this works and seems to be fairly...
2
by: Murt | last post by:
if i perform a sort on an array, how do i get the sorted array to be displayed in a listbox? thanks murt
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
6
by: Zoro | last post by:
I come from the Delphi world and there we had a very useful component called TStringList which was a dynamic string array which had a 'sorted' property and 'duplicate' property and it was great for...
2
by: IcedDante | last post by:
Working with a sorted group, the inability to use following-sibling (which uses Document Order) and convert an RTF (not avaible with the Parser that we are using) hampered our ability to solve the...
0
by: chudq | last post by:
>From GridView's property, these are styles available such as: AlternatingRowStyle EditRowStyle .... I defined these styles in my css file. However, when I set my GridView to a sorted...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.