Filter in datatable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Uri Dimant

    #1

    Filter in datatable

    Hello
    We use VS 2005.
    I fill a data table with simple data from database (one table) which has one
    column called 'flag' filtering by numbers as 1,2,3.
    Now that I have all data in data table I'd like to filter it by value in
    'flag' column. I have three datagrid views on my form and would like to
    fill each grid with filtered data. I mean
    Sub FillDataGrid (dt as datatable)

    with Grid1
    dt.DefaultView. RowFilter = "(TestTypeI D = " & cmbTestTypes.Se lectedValue & "
    AND flag=1 )"

    DataBindings.Cl ear()

    ..DataSource = dt.DefaultView

    end with

    with Grid2
    dt.DefaultView. RowFilter = "(TestTypeI D = " & cmbTestTypes.Se lectedValue & "
    AND flag=2)"

    DataBindings.Cl ear()

    ..DataSource = dt.DefaultView

    end with

    end sub

    My question is why I get for all grids the last filtered data table . I the
    above case I get the data filered by FLAG=2 for Grid1 as well?

    How to solve the problem?

    Thank you




  • =?Utf-8?B?TmltZXNo?=

    #2
    RE: Filter in datatable

    Hi,
    since you are using the same datatable to bind the data to both the grids,
    as soon as you change the row filter, all the grids that are bound to the
    datatable will refresh the data, so you will see the same data in both the
    grids.

    you can solve this problem by declaring multiple dataview objects and
    setting the filters on these views instead of the data tables default view.
    bind the data grids to the data views thus created, instead of binding to the
    dataset.
    http://msdn2.microsoft.com/en-us/lib....dataview.aspx

    hope this helps,

    Cheers,
    Nimesh


    "Uri Dimant" wrote:
    Hello
    We use VS 2005.
    I fill a data table with simple data from database (one table) which has one
    column called 'flag' filtering by numbers as 1,2,3.
    Now that I have all data in data table I'd like to filter it by value in
    'flag' column. I have three datagrid views on my form and would like to
    fill each grid with filtered data. I mean
    Sub FillDataGrid (dt as datatable)
    >
    with Grid1
    dt.DefaultView. RowFilter = "(TestTypeI D = " & cmbTestTypes.Se lectedValue & "
    AND flag=1 )"
    >
    DataBindings.Cl ear()
    >
    ..DataSource = dt.DefaultView
    >
    end with
    >
    with Grid2
    dt.DefaultView. RowFilter = "(TestTypeI D = " & cmbTestTypes.Se lectedValue & "
    AND flag=2)"
    >
    DataBindings.Cl ear()
    >
    ..DataSource = dt.DefaultView
    >
    end with
    >
    end sub
    >
    My question is why I get for all grids the last filtered data table . I the
    above case I get the data filered by FLAG=2 for Grid1 as well?
    >
    How to solve the problem?
    >
    Thank you
    >
    >
    >
    >
    >

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Filter in datatable

      Hi Uri,

      To say Nimesh answer in other words, create at least two extra 'New'
      dataviews.

      Give them all including the default their own filter and you will see that
      you have 3 different grids.

      Cor

      "Uri Dimant" <urid@iscar.co. ilschreef in bericht
      news:OSLGo$u8HH A.5316@TK2MSFTN GP04.phx.gbl...
      Hello
      We use VS 2005.
      I fill a data table with simple data from database (one table) which has
      one column called 'flag' filtering by numbers as 1,2,3.
      Now that I have all data in data table I'd like to filter it by value in
      'flag' column. I have three datagrid views on my form and would like to
      fill each grid with filtered data. I mean
      Sub FillDataGrid (dt as datatable)
      >
      with Grid1
      dt.DefaultView. RowFilter = "(TestTypeI D = " & cmbTestTypes.Se lectedValue &
      " AND flag=1 )"
      >
      DataBindings.Cl ear()
      >
      .DataSource = dt.DefaultView
      >
      end with
      >
      with Grid2
      dt.DefaultView. RowFilter = "(TestTypeI D = " & cmbTestTypes.Se lectedValue &
      " AND flag=2)"
      >
      DataBindings.Cl ear()
      >
      .DataSource = dt.DefaultView
      >
      end with
      >
      end sub
      >
      My question is why I get for all grids the last filtered data table . I
      the above case I get the data filered by FLAG=2 for Grid1 as well?
      >
      How to solve the problem?
      >
      Thank you
      >
      >
      >
      >

      Comment

      • Uri Dimant

        #4
        Re: Filter in datatable

        Thanks Cor and Nimesh. It does work

        "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
        news:46930852-55C2-4C88-A5E5-B2A33C6CCDF4@mi crosoft.com...
        Hi Uri,
        >
        To say Nimesh answer in other words, create at least two extra 'New'
        dataviews.
        >
        Give them all including the default their own filter and you will see that
        you have 3 different grids.
        >
        Cor
        >
        "Uri Dimant" <urid@iscar.co. ilschreef in bericht
        news:OSLGo$u8HH A.5316@TK2MSFTN GP04.phx.gbl...
        >Hello
        >We use VS 2005.
        >I fill a data table with simple data from database (one table) which has
        >one column called 'flag' filtering by numbers as 1,2,3.
        >Now that I have all data in data table I'd like to filter it by value in
        >'flag' column. I have three datagrid views on my form and would like to
        >fill each grid with filtered data. I mean
        >Sub FillDataGrid (dt as datatable)
        >>
        >with Grid1
        >dt.DefaultView .RowFilter = "(TestTypeI D = " & cmbTestTypes.Se lectedValue
        >& " AND flag=1 )"
        >>
        >DataBindings.C lear()
        >>
        >.DataSource = dt.DefaultView
        >>
        >end with
        >>
        >with Grid2
        >dt.DefaultView .RowFilter = "(TestTypeI D = " & cmbTestTypes.Se lectedValue
        >& " AND flag=2)"
        >>
        >DataBindings.C lear()
        >>
        >.DataSource = dt.DefaultView
        >>
        >end with
        >>
        >end sub
        >>
        >My question is why I get for all grids the last filtered data table . I
        >the above case I get the data filered by FLAG=2 for Grid1 as well?
        >>
        >How to solve the problem?
        >>
        >Thank you
        >>
        >>
        >>
        >>
        >

        Comment

        Working...