Click here to Skip to main content
15,920,111 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to Add Two Different Strings to same Index In a Combobox - .NET1.1 Pin
Puneet Bhatnagar11-Dec-08 1:49
Puneet Bhatnagar11-Dec-08 1:49 
GeneralRe: How to Add Two Different Strings to same Index In a Combobox - .NET1.1 Pin
Tom Deketelaere11-Dec-08 2:08
professionalTom Deketelaere11-Dec-08 2:08 
GeneralError Message Pin
Puneet Bhatnagar11-Dec-08 16:17
Puneet Bhatnagar11-Dec-08 16:17 
AnswerRe: How to Add Two Different Strings to same Index In a Combobox - .NET1.1 Pin
riced9-Dec-08 3:15
riced9-Dec-08 3:15 
GeneralRe: How to Add Two Different Strings to same Index In a Combobox - .NET1.1 Pin
Jon_Boy11-Dec-08 4:27
Jon_Boy11-Dec-08 4:27 
GeneralFacing Problem while retrieving Pin
Puneet Bhatnagar11-Dec-08 17:53
Puneet Bhatnagar11-Dec-08 17:53 
GeneralRe: Facing Problem while retrieving Pin
riced12-Dec-08 5:21
riced12-Dec-08 5:21 
GeneralRe: Facing Problem while retrieving Pin
riced16-Dec-08 0:05
riced16-Dec-08 0:05 
I put my thinking head on and came up with the following reason for this seemingly odd behaviour.
Comboboxes (and Listboxes) maintain two collections. One is the Items collection, the other a collection of strings that will be displayed by the list box part of the control.

When you insert (or add) an object two things happen. First a reference to the object is placed in the Items collection. Secondly, the object's ToString() method is called and the result placed in the hidden strings collection. This is what is displayed in the list.
With the code I used the d = New TheData() creates five objects on the heap and references to these objects are placed in Items collection.
When the d = New TheData() lines are commented out, only one object is created on the heap (when d is Dimmed). So all of the references in Items collection point to the same object. This object will have the values last inserted into the list. The selection methods of the combobox operate on the Items collection so they will return what appears to be the last item inserted for all positions.
Because of the two collections, the displayed list can be quite different to what is actually in the Items collection. In the SelectedItemsChanged handler you could update the fields in the item, e.g. by setting secondString to "Impossible", but this would not change the displayed list.
As far as I'm aware you cannot get direct access to the strings collection. The Combobox control maintains this collection when you add, insert or remove items.
Note that the Listbox control behaves in exactly the same way.

Regards
David Rice
GeneralRe: How to Add Two Different Strings to same Index In a Combobox - .NET1.1 Pin
Luc Pattyn9-Dec-08 3:35
sitebuilderLuc Pattyn9-Dec-08 3:35 
Questionvisual basic Pin
jayachandra.c8-Dec-08 19:51
jayachandra.c8-Dec-08 19:51 
AnswerRe: visual basic Pin
Christian Graus8-Dec-08 21:11
protectorChristian Graus8-Dec-08 21:11 
AnswerRe: visual basic Pin
~Khatri Mitesh~9-Dec-08 0:37
~Khatri Mitesh~9-Dec-08 0:37 
AnswerRe: visual basic Pin
Jon_Boy9-Dec-08 3:32
Jon_Boy9-Dec-08 3:32 
Questioncode to save editable data from MSFlexgid to database in vb 6.0. [modified] Pin
sumit52838-Dec-08 19:45
sumit52838-Dec-08 19:45 
AnswerRe: code to save editable data from MSFlexgid to database. Pin
Christian Graus8-Dec-08 21:12
protectorChristian Graus8-Dec-08 21:12 
QuestionCommunication between computers... Pin
Subjugate8-Dec-08 19:00
Subjugate8-Dec-08 19:00 
AnswerRe: Communication between computers... Pin
Steven J Jowett9-Dec-08 0:11
Steven J Jowett9-Dec-08 0:11 
GeneralRe: Communication between computers... Pin
Subjugate9-Dec-08 16:14
Subjugate9-Dec-08 16:14 
GeneralRe: Communication between computers... Pin
Steven J Jowett10-Dec-08 1:33
Steven J Jowett10-Dec-08 1:33 
GeneralRe: Communication between computers... Pin
Subjugate10-Dec-08 14:14
Subjugate10-Dec-08 14:14 
QuestionVideo Implementation Pin
Johndas8-Dec-08 18:40
Johndas8-Dec-08 18:40 
AnswerRe: Video Implementation Pin
Christian Graus8-Dec-08 19:42
protectorChristian Graus8-Dec-08 19:42 
QuestionCreating a MS Access 2007 Database problem... Pin
VIP-CoMmAnDo8-Dec-08 11:31
VIP-CoMmAnDo8-Dec-08 11:31 
QuestionDrag And Drop Into A Datagrid Pin
Phantom7158-Dec-08 11:22
Phantom7158-Dec-08 11:22 
QuestionAdd records to recordset after executing the stored procedure in vb 6.0 Pin
Parag Raibagkar8-Dec-08 7:17
Parag Raibagkar8-Dec-08 7:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.