private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
foreach (string line in richTextBox2.Lines)
{
string searchValue = line;
searchValue = searchValue.Trim();
dataGridView1.SelectionMode =DataGridViewSelectionMode.FullRowSelect;
try
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if(row.Cells[0].Value.ToString().Trim().Equals(searchValue))//error containing line
{
richTextBox1.Text += (row.Cells[1].Value.ToString().Trim()) + "\n";
}
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
}
答案 0 :(得分:0)
foreach(dataGridView1.Rows中的DataGridViewRow行)
{
如果(row.Cells [0]。价值== NULL) {
中断;
} 别的{
if(row.Cells [0] .Value.ToString()。TrimStart()。TrimEnd()。Equals(searchValue.TrimStar t()。TrimEnd()))
{richTextBox1.Text + =(row.Cells [1] .Value.ToString()。TrimStart()。TrimEnd())+“\ n”;}