Results 1 to 2 of 2

Thread: Filter datagrid (mutliplier filters)

  1. #1
    deca is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Apr 2012
    Posts
    1
    Reputation
    0

    Filter datagrid (mutliplier filters)

    Hello,

    First of all I load an excel file to an datagrid. No prob.
    Then I have 2 'checkedlistboxes', so more choices for an filter.

    I think my code is correct but the filter does'nt work correctly.

    Code how I read the values for the checkedlistboxes and put the values in a string with a filterformat =

    Code:
    Dim s AsString = "TYPE = '"
    If CheckedListBox1.CheckedItems.Count <> 0 Then
    Dim x AsInteger
    For x = 0 To CheckedListBox1.CheckedItems.Count - 1
    s = s & CheckedListBox1.CheckedItems(x).ToString & "' OR TYPE = '"
    Next x
    s = s.Remove(s.Length - 12)
    EndIf
    
    Ok this works correct it gives me ae = "TYPE = 'food' OR TYPE = 'horeca'"
    t
    Then I have a 2nd filter which works the same but it put the values in an other string (t) + it make ae = "REGIO = 'Waregem' OR REGIO = 'Kortrijk'"


    Then I put the 2 strings together and bind an "AND" between so we get "TYPE = 'food' OR TYPE = 'horeca' AND REGIO = 'Waregem' OR REGIO = 'Kortrijk'"


    This is correct because I checked it with a messagebox.
    Put this together happens in the filter below


    Then I put this in a filter , the code is:

    Code:
    Dim dv AsNewDataView
    dv = NewDataView(ExcelDataSet.Tables(0), s & " AND " & t, "TYPE Desc", DataViewRowState.CurrentRows)
    DataGridView1.DataSource = dv
    
    So whats the problem.
    If I check 1 value on the 2 filters. It works correctly. If I check more then it shows not the right result.
    Can it be that the filter only works with 1 or 2 arguments? and not with 3,4,5?

  2. #2
    Lotok is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Location
    Scotland
    Posts
    193
    Reputation
    22
    "(TYPE = 'food' OR TYPE = 'horeca') AND (REGIO = 'Waregem' OR REGIO = 'Kortrijk')"

    Give that a shot

Bookmarks

Posting Permissions

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