none
Dataset RowFilter, Only filters using datasource RRS feed

  • Question

  • I have a dataset which i fill with data from my database,

    Now when i apply a rowfilter and set the datasource to my datagrid it works perfectly.

     

    But i dont want to add it to my datagrid but to a treeview, but however i loop trough the dataset it never filters.

    The idea is then when you type the first letter it get a dataset from the database containing everybody that starts with that letter then when the textbox length is larger then one apply a rowfilter

     

    else if(tb_filter.Text.Length > 1)

    {

    DataView dataView = dataset_filter.Tables[0].DefaultView; //create a dataview from the dataset

     

    dataView.RowFilter = "artiestnaam like '" + tb_filter.Text + "%'";  //set rowfilter

     

    dg_overzichtgroep.DataSource = dataView; //this line normaly doesnt exist its here for testing if it did filter on a datagrid

     

    //loop trough dataset add names to treeview

    for(int i=0; i < dataView.Table.Rows.Count; i++)

    {

    string s = dataView.Table.RowsIdea["artiestNaam"].ToString();

    if(tv_filter.InvokeRequired == true)

    {

    //use invoke to add to the treeview becuase of the seperate thread

    tv_filter.Invoke(new UpdateTextCallback(this.AddToTreeView), new object[]{s});

    }

    else

    {

    tv_filter.Nodes.Add(s);

    }

    }

    }

     

    Example:

     

    Database contains 2 records: "Test", "TTest".

     

    So when i type T in tb_filter the treeview will have Test and TTest,

    Now when i type Te in tb_filter the treeview will have Test and TTest and the datagrid will have Test. (I do clear the treeview)

     

    Im clueless what to do.

     

    Any help would be greatly appreciated.

     

    Friday, December 14, 2007 11:22 AM

All replies

  • Somebody must know this.

     

    Monday, December 17, 2007 7:49 AM
  •  

    The fix if anybody is enterested:

     

    DataView dataView = dataset_filter.Tables[0].DefaultView;
        dataView.RowFilter = "artiestnaam like '" + tb_filter.Text + "%'";

        foreach (DataRowView drv in dataView)
        {
            string s = drv["artiestNaam"].ToString();

         if(tv_filter.InvokeRequired == true)
         {
          //use invoke to add to the treeview becuase of the seperate thread
          tv_filter.Invoke(new UpdateTextCallback(this.AddToTreeView), new object[]{s});
         }
         else
         {
          tv_filter.Nodes.Add(s);
         }
        }

    Tuesday, December 18, 2007 10:04 AM