private void dgvGz_SelectionChanged(object sender, EventArgs e) { if (dgvGz.SelectedRows.Count <= 0) { return; } string gzid = dgvGz.SelectedRows[0].Cells["gzid"].Value.ToString().Trim(); string whysid = xtBiz.GetWhysid(gzid); for (int i = 0; i < dgvWhys.Rows.Count; i++) { string strWhysid = dgvWhys.Rows[i].Cells["whysid"].Value.ToString().Trim(); if (whysid == strWhysid) { dgvWhys.Rows[i].DefaultCellStyle.ForeColor = Color.Red; } else { dgvWhys.Rows[i].DefaultCellStyle.ForeColor = Color.Black; } } }