Hi guys,

ive got a datagridview populated, in a column of names, in a textbox i want to write a name, and on btn click i want to check the DGV for that name, can someone point me in the right direction please

what i have so far, but i think im totallly off lol

int i = dgv_Cust.Rows.Count;               
            for (i = 0; i < dgv_Cust.Rows.Count; i++)
            //    Account = Convert.ToString(dgv_Cust.Rows[i].Cells[8].Value);

            if (dgv_Cust.Rows[i].Cells[8].Value == "TOM")
                if (tbox_Type.Text == "TOM") ;
                MessageBox.Show("maybe this is the way?");

many thanks in advance :)

3 Years
Discussion Span
Last Post by Sammys.Man

That's a little bit of a backwards way to do it.

Follow this kind of logic instead:

Foreach row in your DGV (yes you can use the foreach command)
Get the value of the cell in the Name column
If this value equals the value of the text box
-> Return your result (I don't know what this is)
-> Check the next row.


foreach(row in dgv)
    if(row.NameCell.Value == textbox.Text)
        return result;

Note that that's pseudo code, not something you can copy-paste


ive got a datagridview populated

What dataSources are used to populate the DataGridView? There are number of ways to do so,

  1. Compare input value against the dataSource (array,List<T>, DataTable etc) that is used to populate the DtaGridView.
  2. Traverse the DataGridView.Rows collection (you've tried).

hi guys, i think im on the right track, thanks to KetsueKiame's advice, i went back to the drawing board and came up with this


                foreach (DataGridViewRow row in dgv_Cust.Rows)
                    if (row.Cells[7].Value.ToString().Equals(tbox_Type.Text))

although its rough and un finished it is working, i will leave this forum unmarked for now, until the entire code is working,

many thanks :)

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.