473,763 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Da taRowView". 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.DataSour ce = dsInfo.Tables(0 )

the value of cbTest.Datasour ce 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 1493
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
(ArgumentExcept ion) 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/
frlrfsystemwind owsformscombobo xclasssortedtop ic.asp . 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
(ArgumentExcept ion) 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/
frlrfsystemwind owsformscombobo xclasssortedtop ic.asp . 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
2517
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 property of the 'ListMemberObject' which is instrumental in the sort to be modified unbeknownst to the list thereby defeating the sort. One way to keep the list sorted is to add a 'ParentList' property to the ListMemberObject and notify that...
4
5153
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 items). - indexed by value index or by key (2 indexers) - sortable by key or a secondary key - supporting foreach loops
10
11623
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 efficent. The idea was simple, insert an integer into a list that has already been sorted. private int _list; .... public void Insert(int value) { int tempArray;
2
1959
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
4953
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 the column order of the datatable). I also allow the user to click on a column header to sort the datagrid by that column. I need to identify the row and column in the datatable when the user clicks on a cell in the datagrid. Using the...
6
13072
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 maintaining ordered lists allowing or disallowing duplicates. Is there something similar in C#? What I need in particular is an integer list that will keep itself sorted automatically when i add items and that will ignore attempts to add a...
2
2660
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 following problem. Consider the following set of Data: <example> <Credentials time="3"> <UserId>kiss</UserId> </Credentials> <Credentials time="1" break="true">
0
1078
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 one(Enabling Sorting property), the default header color becomes "blue". This color is very hard to see again my other style settings defined in css. I cannot find a way to customize it in my css
8
2596
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; m_ResultArray.Add ( aFoundObject);
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9998
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.