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 :)

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)
Else
-> Check the next row.

So;

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).

ok cool, thanks
i knew my code wasn't right lol, i will have a play with it

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

 try
            {

                foreach (DataGridViewRow row in dgv_Cust.Rows)
                {
                    if (row.Cells[7].Value.ToString().Equals(tbox_Type.Text))
                    {
                        MessageBox.Show("Matched");
                    }
                }
            }
            catch
            {
            }

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.