filter rows in a bound datagrid

  • Thread starter Thread starter phonl
  • Start date Start date
P

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.
 
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.
 
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?
 
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."
 
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.
 
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%'"
 
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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top