B
Booney440
Guest
I am pasting data in a DGV and want to search the first column [0]. I am using textbox change the code i have so far only highlights the row I need it to only show the rows it equals. This is what I have so far.
private void tb_Search_TextChanged(object sender, EventArgs e)
{
string searchValue = tb_Search.Text;
int rowIndex = -1;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
try
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[0].Value.ToString().Contains(searchValue))
{
rowIndex = row.Index;
dataGridView1.ClearSelection();
row.Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex;
dataGridView1.Focus();
break;
}
}
}
catch (Exception)
{
MessageBox.Show("No solutions with that name.");
}
}
}
}
Booney440
Continue reading...
private void tb_Search_TextChanged(object sender, EventArgs e)
{
string searchValue = tb_Search.Text;
int rowIndex = -1;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
try
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[0].Value.ToString().Contains(searchValue))
{
rowIndex = row.Index;
dataGridView1.ClearSelection();
row.Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex;
dataGridView1.Focus();
break;
}
}
}
catch (Exception)
{
MessageBox.Show("No solutions with that name.");
}
}
}
}
Booney440
Continue reading...