i want to comare textbox value with datagridview items before adding this textbox value in datagridview

Recommended Answers

All 5 Replies

Hi Ahmed 43, welcome at DaniWeb.
What difficuties do you have with looping through all the DataGridView cells and comparing each value with that of the TextBox?

code plz in c#

Have you tried anything at all yet? This is a straightforward loop.

Hi try something using foreach loops in your DataGridView and then compare using

foreach (DataGridViewRow r in myDataGridView.Rows)
{
   if (r.Cells["ColumnName"].Value.ToString() == myTextBox.Text)
   {
      // Whatever you wish to do with this condition matching.
   }
}

Hope that helps.

Speaking off KM499's answer, you can also do something like

string VarName = dataGridView1[1, 1].Value.ToString();

Where [1, 1] is the column and row index (in that order). This allows you to choose what ever cells you want to look at

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.