473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

filter rows in a bound datagrid

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.
Mar 2 '06 #1
6 15200
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.

Mar 2 '06 #2
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?
"Virgil" <vs*******@trilliumteam.com> wrote in message
news:11********************@t39g2000cwt.googlegrou ps.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.

Mar 2 '06 #3
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.

Mar 3 '06 #4
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."

Mar 3 '06 #5
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%'"
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:mR**************@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."

Mar 3 '06 #6
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/de...us/cpref/html/
frlrfsystemdatadatacolumnclassexpressiontopic.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Mar 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
3
by: BBFrost | last post by:
Ok, I know how to count the number of selected datagrid rows using the code below. What has me stumped is how to determine when the selected rows within a datagrid have been changed. The...
0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Fred Morrison | last post by:
Is it just me or is there something grossly wrong with the Windows Forms DataGrid control that won't tell me the row count inside it? I'm not talking about just visible rows (what the heck good is...
10
by: Aaron Smith | last post by:
If I have a datagrid and the bound data file only have 4 rows in it, the grid will show the 4 rows. However, there is blank space below that until it reaches the bottom of the grid. Is there a way...
3
by: Gerhard | last post by:
I would like a DataGrid I am using to show a default number of rows (10) with the heading, even if the dataset it is bound to returns less than that number of rows (0-9). It is a databound grid...
1
by: lgalumbres | last post by:
Hi, I have a datagrid on Winform that is bound to a datatable. In essence, what I would like to do is that when a user inputs a number into a textbox control for example 5 then 5 empty rows...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.