I have a datagridview with data in it. I want to search the whole datagridview with a searchbox.

This is the code I am using but it only searches the 'model' column not also the 'make' column.

DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' ";
            Dv.RowFilter = " Model LIKE '%" + makeBox.Text + "%' ";
            dataGridView1.DataSource = Dv;

HMM, I am not sure but try this.

DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' OR Model LIKE '%" + makeBox.Text + "%' ";
            dataGridView1.DataSource = Dv;

Make another TextBox ModelBox

DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' OR Model LIKE '%" + ModelBox.Text + "%' ";
            dataGridView1.DataSource = Dv;

or parse them with substring(). // The code I am wrinting is without compiler so there may be some mistakes.

string make = makeBox.text.substring(0,makeBox.indexOf(' '));
string model =  makeBox.text.substring(makeBox.indexOf(' ')+1, makeBox.Length - (makeBox.indexOf(' ')+1));

          DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + make + "%' OR Model LIKE '%" + model + "%' ";
            dataGridView1.DataSource = Dv;

but you will have to make sure the user leaves a space and they don't type "Accord Honda".

You should also make the the 'OR' in the filter to 'AND' if the space is detected. and you will also have to make sure if there is no spaces detected that it doesn't do the .substring. Very simple stuff with if statements.

I suggest you choose the first option of making a textbox called modelBox.

If you are making an Spare Parts inventory search program I suggest you add Spare Part number.

Finiti, Thanks for the tips.

I did a modelbox also but I want them to be connected to each other.

For example when I write 'Honda' in the makebox and then something else in the modelbox it only shows the value from modelbox. I don't want it to restart from start when I start writing on the other box.

Dv.RowFilter = " Make LIKE '%" + [B]makeBox.Text[/B] + "%' OR Model LIKE '%" + [B]ModelBox.Text [/B]+ "%'

Dv.RowFilter = " Make LIKE '%" + [B]makeBox.Text[/B] + "%' OR Model LIKE '%" + [B]ModelBox.Text [/B]+ "%'

I can't use OR operator if I use maybe 4 searchboxes. How do I do then?

Look at this image:
http://img97.imageshack.us/img97/1448/asdfgvt.jpg

Why does it also show 'Honda accord'? I want it to show just 'Honda Civic'.

do you the concept
++ make +
-- make +
-+ make -
+- make -

just read the SQL you did

Make LIKE '%" + makeBox.Text + "%' [B]OR[/B] Model LIKE '%" + ModelBox.Text + "%'

This in English is get Items where Make is like "Honda" OR Model is Like "Accord"

So you will get all values that are either Honda or Accord.

If you want it to find only where Make is Honda and Model is Accord you would do this:

Make LIKE '%" + makeBox.Text + "%' [B]AND[/B] Model LIKE '%" + ModelBox.Text + "%'

when you want to add more criteria filters just add it like this

Make LIKE '%" + makeBox.Text + "%' OR Model LIKE '%" + ModelBox.Text + "%' OR Part LIKE '%" + PartBox.Text + "%'"

and so on

Thank you very much finito for the help I have now fixed the problem.

Thank you very much finito for the help I have now fixed the problem.

nps your welcome, please mark as solved.