Hi there,
Am trying to get an entire row of my datagridview selected, because one of its columns contains a value similar to a value in my textbox1.text.
Any help will be appreciated.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 13, 2015, 1:05 AM EST
you can get on selection_changed event of datagridview.
i.e.
(datagridview.selecteditem as
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 13, 2015, 1:57 AM EST
string val1= GridView1.SelectedRow.Cells[0].Text;
string val2= GridView1.SelectedRow.Cells[1].Text;
Vikram AgrawalRank #4,713 · 329 reputationPosted Jan 13, 2015, 3:07 AM EST
you can do this in GridViewSelectedIndexChange event.
in that you will get the selected row and in that row you can find your column's value and match with textbox.
like
string txt = (grid1.SelectedRow.FindControl("MyLabel") as Label ).Text;
Marvin kakuruRank #3,979 · 374 reputationPosted Jan 13, 2015, 4:05 AM EST
private void btnSearch_Click(object sender, EventArgs e) { string searchValue = textBox1.Text; dgvProjects.SelectionMode = DataGridViewSelectionMode.FullRowSelect; try { foreach (DataGridViewRow row in dgvProjects.Rows) { if (row.Cells[2].Value.ToString().Equals(searchValue)) { row.Selected = true; break; } } } catch (Exception exc) { MessageBox.Show(exc.Message); } }VulpesRank #55 · 29.2K reputationPosted Jan 13, 2015, 4:06 AM EST
// in Form_Load
// in a button Click, textBox Leave or wherever you want to put it
int k = 0; // or whatever
Sam HobbsRank #107 · 20.5K reputationPosted Jan 17, 2015, 10:21 AM EST