filter a column with multiple values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nev
    Contributor
    • Oct 2007
    • 251

    filter a column with multiple values

    i declared 2 datatables:

    dim dtt1 as datatable = ds.datatable1
    dim dtt2 as datatable = ds.datatable2

    dtt1 has firstname, lastname columns
    dtt2 has firstname column

    when i filter dtt1 by lastname, there will be a lot of firstnames

    what can i do to filter dtt2 by all those firstnames?

    i can filter a column by 1 value like .rowfilter= "firstname= '" & firstname1 & "'"

    i want to know how to filter a column with multiple values (taking note that the firstname may have none to a lot of values). if i do this...

    .rowfilter="fir stname='" & fn1 & "AND firstname='" & fn2 & " AND so on...'"

    this will take forever. is there any way i could filter dtt2 with all the firstnames i got after filtering dtt1?
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Iterate throug each row of the grid
    and check if the isRowVisible(Ro wHandle) is true.
    then use that row to fetch the id,s and create the AND statment for the next grid

    I am using the context of gridview beacause it has the RowFilter Property, while datatables i think dont have that.

    Comment

    • nev
      Contributor
      • Oct 2007
      • 251

      #3
      Originally posted by Shashi Sadasivan
      Iterate throug each row of the grid
      and check if the isRowVisible(Ro wHandle) is true.
      then use that row to fetch the id,s and create the AND statment for the next grid

      I am using the context of gridview beacause it has the RowFilter Property, while datatables i think dont have that.
      ok, i'll check it out. thank you.

      Comment

      • nev
        Contributor
        • Oct 2007
        • 251

        #4
        i was thinking is there a way i can relate the 2 datatables so that if i filter dtt1, dtt2 filters itself with respect to the firstnames in dtt1?

        it is because if i do code like the one suggested, and say i have over 100 records, that will really take time to process.

        Comment

        • Shashi Sadasivan
          Recognized Expert Top Contributor
          • Aug 2007
          • 1435

          #5
          Hi,
          Sorry about my previous post.
          I have been using some third party tools since I plunged into windows apps.
          and they have beautiful support for filtering.

          Coming back to your query, in your case you might be using a dataView to change the filter.

          once the filter is changed, I think the ListChanged Event of the dataview is triggered.

          Once you reach here you can check if the row isvisible as mentioned before.

          cheers

          Comment

          • nev
            Contributor
            • Oct 2007
            • 251

            #6
            Originally posted by Shashi Sadasivan
            Hi,
            Sorry about my previous post.
            I have been using some third party tools since I plunged into windows apps.
            and they have beautiful support for filtering.

            Coming back to your query, in your case you might be using a dataView to change the filter.

            once the filter is changed, I think the ListChanged Event of the dataview is triggered.

            Once you reach here you can check if the row isvisible as mentioned before.

            cheers
            hello, actually i already did the code as suggested. what bothers me is that when time comes there are a lot of firstname records, my iterating for loop might take time to process them. is there a way to create a relationship to dtt1 and dtt2 so that dtt2 gets filtered when i filter dtt1? how do you do code to create a relation?

            Comment

            • Shashi Sadasivan
              Recognized Expert Top Contributor
              • Aug 2007
              • 1435

              #7
              i think the filter should be of type
              FirstName OR firstname2 OR firstname3.....
              and not
              FirstName AND firstname2 AND firstname3.....

              with the AND you may get no items listed.

              Seems that the filter you reate will be the same filter for the second table too.
              So build a filter string, and assign that to both the datatables!

              if you filter table 1 with names fred and jones
              then you want table 2 to contain values with names fred and jones.
              so the same string should apply.

              Hope i got it right

              Comment

              • nev
                Contributor
                • Oct 2007
                • 251

                #8
                oh i forgot to mention i used OR :-)

                Comment

                Working...