|
-
Feb 5th, 2009, 09:42 AM
#1
Thread Starter
Hyperactive Member
[2008] Two listboxes and a master dataset with filtering
hopefully somebody can point out what i'm missing. I have two list boxes populated by a master list and an excluded list. the excluded list is pulled first from a csv field in a table, and is inserted in to the excluded listbox. it's workin great.
The master list contains all items and is pulled from a dataset, but should filter out those in the excluded list and populate the second list box with only those values that are NOT listed in the excluded box.
I'm trying a for/next loop and i think i'm close but this one is becoming a pain. Here's the code:
Code:
' Declare Variables
Dim categorydr As DataRow
Dim categorydt, As DataTable
Dim categoryindex, categoryposition As Integer = 0
Dim categoryfound As Integer = 0
'Select the CSV field in my database
categorylistitem = Trim(MaterialTableAdapter.GetData.Item(lbMaterials.SelectedIndex).Permitted_Categories)
'Prep the field to parse out the comma's and insert into the not permitted listbox
Dim categorystr As String = categorylistitem
'actually do the parsing
Do
categoryindex = categorystr.IndexOf(","c, categoryindex)
If categoryindex = -1 Then Exit Do
categoryindex += 1
categoryfound += 1
Loop
'Fill the not permitted listbox
For categorycount = 0 To categoryfound
categoryparselistitem = Split(categorylistitem, ",")(categoryposition)
lbCategoriesNotPermitted.Items.Add(Trim(categoryparselistitem))
categoryposition += 1
Next
'Fill the permitted List Box with values that aren't in the not permitted box, right now it does all or fails
categorydt = MyDataset.Tables("Category")
For Each categorydr In categorydt.Rows
For Each stringitem In lbCategoriesNotPermitted()
If categorydr.Item("Description").ToString <> lbCategoriesNotPermitted.Items.Item() Then
lbCategoriesPermitted.Items.Add(categorydr("Category"))
End If
Next
Next
the listboxes as you can see are lbCategoriesPermitted and lbCategoriesNotPermitted accordingly.
The idea is that the master list is contained in categorydt, and it is - if i were to exclude the nested for next loop at the end of the code and just do the .add, it fills it perfectly but includes ALL items in the dataset - what i am trying to get it to do is scan the non-permitted items, compare them with the master, then populate the permitted items listbox MINUS that item and continue through the loop until done.
thanks all for anyone who has some insight in to this - i feel i'm close, but just can't quite get it......
Last edited by trevorjeaton; Feb 5th, 2009 at 10:39 AM.
-
Feb 5th, 2009, 09:55 AM
#2
Thread Starter
Hyperactive Member
Re: [2008] Two listboxes and a master dataset with filtering
oh and also to add, in case it comes up, the table in question is called category, but the field that is being worked on within that table is also called category, so it may cause a little confusion - the main thing for me is the proper format of that final for/next loop - all other code is doing exactly as it it should.
thanks again everyone.
-
Feb 5th, 2009, 10:20 AM
#3
Thread Starter
Hyperactive Member
Re: [2008] Two listboxes and a master dataset with filtering
sorry folks - the previous one marked resolved was actually a duplicate thread by accident. my bad. As i was saying, for this one, the main thing is that final for/next loop.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|