Results 1 to 3 of 3

Thread: [2008] Two listboxes and a master dataset with filtering

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Burlington, ON, Canada
    Posts
    343

    [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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width