Home All Groups Group Topic Archive Search About

filter rows in a bound datagrid

Author
2 Mar 2006 5:16 PM
phonl
VB.Net 2005

I have a bound datagrid with a list of names.  I want to add a button that
will filter the names so that only the names that start with "H" will
display.  How would I do that?

Thanks for help.

Author
2 Mar 2006 6:04 PM
Virgil
I would:
1) place the list of names in a DataTable
2) create a DataView based on the DataTable
3) bind the grid to the DataView

Then, when the user clicks the button, you can simpley change the
Filter property of the DataView and your grid will change accordingly.
Author
2 Mar 2006 8:45 PM
phonl
I have my grid bound to an Access database via the datawizard in vb.net
2005.  I don't think I can bind to a view?  Can I?


Show quoteHide quote
"Virgil" <vschle***@trilliumteam.com> wrote in message
news:1141322693.971155.8630@t39g2000cwt.googlegroups.com...
>I would:
> 1) place the list of names in a DataTable
> 2) create a DataView based on the DataTable
> 3) bind the grid to the DataView
>
> Then, when the user clicks the button, you can simpley change the
> Filter property of the DataView and your grid will change accordingly.
>
Author
3 Mar 2006 2:27 AM
Kevin Yu [MSFT]
Hi phonl,

Yes, you can still bind to a view. You need to drag and drop a DataView
from the toolbox. (If it is not in the toolbox, right click in the toolbox
and add it using Choose Items.)

Then you have to set the DataView.Table property to the DataTable that
contains data, and set the grid data source to the DataView. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Author
3 Mar 2006 2:32 PM
phonl
Thank you Kevin and Devlei.

I like the DataView.   I would like to know more about the
"DataView.RowFilter".  It seems to be limited so I can't do "AND", "OR" etc
to do more complex filters.  Is correct; or am I not using the proper
syntax?

DataView1.RowFilter = "REQUEST_BY = 'Pete' AND OBJECTIVES = '7A'"
or
DataView1.RowFilter = "REQUEST_BY = 'Pete' AND OBJECTIVES LIKE '7%'"


Show quoteHide quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:mRoWf8nPGHA.5536@TK2MSFTNGXA03.phx.gbl...

> Hi phonl,
>
> Yes, you can still bind to a view. You need to drag and drop a DataView
> from the toolbox. (If it is not in the toolbox, right click in the toolbox
> and add it using Choose Items.)
>
> Then you have to set the DataView.Table property to the DataTable that
> contains data, and set the grid data source to the DataView. HTH.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
Author
6 Mar 2006 3:18 AM
Kevin Yu [MSFT]
Hi Phonl,

We can use AND, OR operators in the RowFilter. Actually, the RowFilter
property is using the same syntax as the DataColumn.Expression property.
You can check the following link for more information on the syntax of it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatacolumnclassexpressiontopic.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Author
3 Mar 2006 3:59 AM
Devlei
Fill a Dataset with your Access data, then add a DataView object, and
set its Table property to the "Dataset.Table".  Then use the
DataView.RowFilter property to filter like, "Name = 'Harry'".  The
Datagrid.DataSource property must be set to the DataView.

Hope that helps.