Has anyone done this before?

G

Guest

Hi Folks

I am creating a basic form with a textboxes (txtSurname) and a datagrid

I want my datagrid to contain a list on clients that already exist on my database. (this is ok)

What i now want to do is to dynamically filter the datagrid according to what the user enters in the surname textbox. For example if the first letter they enter is 'B' I want the datagrid to now only contain a list of surnames beginning with 'B'. I want this to continue with every letter the user selects. Can anyone tell me if this is possible to do using these controls and how i may go about doin this???

Once the datagrid is filtered down to 0 or more surnames i want the user to be able to click on any row and then click a 'OK' button so i can reuse this guests details instead of re-entering everything

If anyone has done anything similar and has examples or advise i would greatly appreciate it

Many thx
 
W

William Ryan eMVP

Hi Bhavna:

Bind your DataGrid to a DataView. Then on the textchanged event of the
textbox, you can set the DataView's rowfilter to either the TextBox's text
(which will only yield results when the text matches) or you can use a Like
in the expression of the rowfilter . DataView.RowFilter =
"FiteringColumnName Like('*" + textBox.Text + "'"

HTH,

Bill
Bhavna said:
Hi Folks,


I am creating a basic form with a textboxes (txtSurname) and a datagrid.

I want my datagrid to contain a list on clients that already exist on my database. (this is ok).

What i now want to do is to dynamically filter the datagrid according to
what the user enters in the surname textbox. For example if the first letter
they enter is 'B' I want the datagrid to now only contain a list of surnames
beginning with 'B'. I want this to continue with every letter the user
selects. Can anyone tell me if this is possible to do using these controls
and how i may go about doin this????
Once the datagrid is filtered down to 0 or more surnames i want the user
to be able to click on any row and then click a 'OK' button so i can reuse
this guests details instead of re-entering everything.
 
G

Guest

Hi William

I have tried the method u suggested but it does not seem to wor
The steps i took are below
I created a dataset by running a sql statement. This is ok
I then declared a dataview and created it and assigned it to the datagrid. This is displayed ok

I then added the following code to the txtSurname.TextChanged even
ClientDV.RowFilter = "Surname Like ('*" + txtSurname.Text + "')
Surname is the 2nd column in the dataview that i want to filter data on

The problem i have is that the data is not been filtered properly!
I have surnames that begin with 'P' but when i enter 'p' in the surname textbox i get a surname that begins with an 'S' !!!

Do you have any ideas what i could be doin wrong?

Could this be to do with the fact that im using the 'Like' statement?

can anyone plz help me
 
G

Guest

Hi

I think i have figured out what the filter is doing. It is working but it seems to be filtering the surname in reverse order

i.e if i have a surname called 'Smith' in my dataview..
if i type 'e' in the txtsurname Smith will be returned as 'e' is the last letter in the surname!!

Is there anyway i can reverse the filter to search via the start of the surname instead of the end?

Here is my current filter code...
ClientDV.RowFilter = "Surname Like ('*" + txtSurname.Text + "')

Can anyone hlp?
 
G

Gary Milton

Bhanva,

Put the wildcard character at the end of the surname, not the beginning,
so...

ClientDV.RowFilter = "Surname Like ('" + txtSurname.Text + "*')"

Gary

Bhanva said:
Hi,

I think i have figured out what the filter is doing. It is working but it
seems to be filtering the surname in reverse order.
 
W

William Ryan eMVP

That's because WildCard P will return everything that has a p in it. Sports
will be returns, Beep will be returned etc. Your wildcard is the problem.
Where Left(" & txtSurname.text &",1) = 'P' or something like that should
work though.


Bhavna said:
Hi William,

I have tried the method u suggested but it does not seem to work
The steps i took are below:
I created a dataset by running a sql statement. This is ok.
I then declared a dataview and created it and assigned it to the datagrid. This is displayed ok.

I then added the following code to the txtSurname.TextChanged event
ClientDV.RowFilter = "Surname Like ('*" + txtSurname.Text + "')"
Surname is the 2nd column in the dataview that i want to filter data on.

The problem i have is that the data is not been filtered properly!!
I have surnames that begin with 'P' but when i enter 'p' in the surname
textbox i get a surname that begins with an 'S' !!!!
 

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

Top