|
-
Feb 5th, 2009, 09:42 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [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 excluded 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 excluded listbox
For categorycount = 0 To categoryfound
categoryparselistitem = Split(categorylistitem, ",")(categoryposition)
lbCategoriesNotPermitted.Items.Add(Trim(categoryparselistitem))
categoryposition += 1
Next
'Fill the Not Excluded List Box with values NOT in the excluded 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("Description"))
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 and just do the .add, it fills it perfectly - 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 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......
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
|