Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi, this my first post, but:

OK, I have a CheckedListbox being populated from a DataSet.

I have the 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

newdatarow(0) = item.PositionInListBox

So what can I do?

Edited by KingAce
Posted

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

Software bugs are impossible to detect by anybody except the end user.
Posted
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...

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

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

Posted

"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

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...