New Posts New Posts RSS Feed: Filtering Rows in DataGridView using BindingSource
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Filtering Rows in DataGridView using BindingSource

 Post Reply Post Reply
Author
Tich View Drop Down
Newbie
Newbie


Joined: 19-Jul-2007
Posts: 11
Post Options Post Options   Quote Tich Quote  Post ReplyReply Direct Link To This Post Topic: Filtering Rows in DataGridView using BindingSource
    Posted: 05-Sep-2007 at 6:48am

Thanks I will try that approach, but the code I have works if  I only use a DataGridView and a BindingSource. Trouble comes when I use a DataGridView BindingManager hooked up to a BindingSource and get the data from an entity list.  

The code below is an edited extract from the class frmSearchGrid() which allows me to search any DataGridView because the code generates the search parameter (strFilter) dynamically.

//constructor
frmSearchGrid( DataGridView _DataGrid, BindingSource _BS)  
…..

SearchGrid ()
{
   ….

            // cboColumn is a combo box that lists all the visible columns in the DataGridView

 String strFilter = "[" +      cboColumn.SelectedItem.ToString() + "]" + " = " + "'" +    txtSearch.Text.ToString() + "'";

                   _BS.Filter = strFilter;

             if ( _DataGrid.Rows.Count == 0)

             {

// search item not found 
       _BS.RemoveFilter();

                        MsgBox.Show(" Search item not found ");

                        txtSearch.Focus();

                        return;

              }

            else

            {  

                        // search item found

 this.Close();

                                return;

            }
  ….

}

 



Edited by Tich - 05-Sep-2007 at 7:01am
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 04-Sep-2007 at 5:48pm
Tich:
 
You can't use the Filter property of the BindingSource, as there is no syntax defined for it.  It's one of those raw .NET facilities that require custom implementation to be usable.
 
Instead, assign an EntityList<T> to the BindingSource as its DataSource,
then do a ReplaceRange() on the EntityList whenever you need to filter the rows. E.g.,
 
EntityList<Employee> mEmployees = new EntityList<Employee>();
mEmployeesBindingSource.Datasource = mEmployees;
RdbQuery anRdbQuery = new RdbQuery(typeof(Employee));
anRdbQuery.AddClause(BirthDateEntityColumn, EntityQueryOp.GT, new DateTime(1950, 1, 1));
mEmployees.ReplaceRange(PersistenceManager.DefaultManager.GetEntities<Employee>(anRdbQuery));
 
 
Greg Dunn
IdeaBlade

 
Back to Top
Tich View Drop Down
Newbie
Newbie


Joined: 19-Jul-2007
Posts: 11
Post Options Post Options   Quote Tich Quote  Post ReplyReply Direct Link To This Post Posted: 04-Sep-2007 at 7:25am

I have a DataGridView hooked up to a  DataGridViewBindingManager which has a BindingSource when I set the filter property of the BindingSource the rows displayed in the DataGridView are not filtered

help !   Unhappy

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down