Position in listbox?

KingAce

Newcomer
Joined
Jun 26, 2005
Messages
7
Hi, this my first post, but:
OK, I have a CheckedListbox being populated from a DataSet.
I have the code:
Code:
Dim item As Object
 For Each item In CheckedListBox1.SelectedItems

 Next
Now, I want each item to be added to the DataSet based on its position in the ListBox.
Obviously, I cant say
Code:
newdatarow(0) = item.PositionInListBox
So what can I do?
 
Last edited:
Ok...
First this... you can't add any data to a DataSet... Only to a DataTable.

Now, from what I understood, you populate a ListBox from a DataTable on a DataSet, right?
Then... you want to add the items on that ListBox back to the same DataTable or to a new DataTable on the same DataSet?

Alex :p
 
AlexCode said:
Ok...
First this... you can't add any data to a DataSet... Only to a DataTable.

Now, from what I understood, you populate a ListBox from a DataTable on a DataSet, right?
Then... you want to add the items on that ListBox back to the same DataTable or to a new DataTable on the same DataSet?

Alex :p
OK, um...
Sorry, I mean datatable, I'm not brand new to ADO.NET, sorry, "Syntax Error" on my part. Lol. So yeah I am populating the checkedlistbox from a datatable on a dataset. But I'm working with a relationship or a associative entity - in other words, the filled listbox is sorted by the ID Column in Table 1, (displaying a different column though) and my Relationship Entity is called Table1@Table2 or whatever. So I'm adding the Row to the Table1@Table2 table, but I need to figure out which position the checked item is in in the ListBox. THis would be relatively simple, but there is an opportunity to select multiple items.
SO going back to my code, I'm using a loop...
Code:
Dim item as object
For Each item In CheckedBox1.SelectedItems
***
Next
I need to figure out the code for finding the current position in the listbox.
My problem is theres no such thing as
Code:
Dim item as CheckedListBoxItem
So the code for finding the current position needs to go where the *** is above.

On a different note, I see your in portugal; I'm portuguese! In fact my grandparents (who live in Cascais) were just here, (I live in America atm).

TIA
Adam
 
"On a different note, I see your in portugal; I'm portuguese! In fact my grandparents (who live in Cascais) were just here, (I live in America atm)."
NICE! Small country by with people spread all over :))))
I'm from Setubal... about 50 or 60 Km South from Cascais...

Now for you question...
The CheckListBox gives you 2 collections that give you pretty much all you need to do that:
Me.CheckedListBox1.CheckedIndices()
Me.CheckedListBox1.CheckedItems()

I believe that the first one is the one you need now... it gives you the index of the checked items indexes. The second gives you the actual selected objects.

Yet I didn't undestood what you're trying to pull here.
Me.CheckedListBox1.CheckedItems() will five you a collection of datarows, so you can get the ID (primary key) column value on the source too...

Is this it?

Alex :p
 
Back
Top