null値をチェックしていないと仮定しています。これらのヌル値チェックを追加すると、あなたが記述したとおりに動作するように見えます。行にToString()
メソッドを追加すると、の後にcell.Value == searchValue
の後に比較が成功します。また、休憩は必要ありません。
DisplayGridView.ClearSelection();
foreach (DataGridViewRow row in DisplayGridView.Rows) {
foreach (DataGridViewCell cell in row.Cells) {
if (cell.Value != null) {
if (cell.Value.ToString() == searchValue) {
cell.Selected = true;
}
}
}
}
次の方法
DisplayGridView.ClearSelection();
foreach (DataGridViewRow row in DisplayGridView.Rows) {
for (int i = 0; i < DisplayGridView.Columns.Count; i++) {
if (row.Cells[i].Value != null) {
if (row.Cells[i].Value.ToString().Equals(searchValue)) {
row.Cells[i].Selected = true;
}
}
}
}
検索文字列がセルの文字列に含まれている場合、セルを強調表示したい場合は、あなただけには含まれていequalsメソッドを変更する必要があります。
DisplayGridView.ClearSelection();
foreach (DataGridViewRow row in DisplayGridView.Rows) {
foreach (DataGridViewCell cell in row.Cells) {
if (cell.Value != null) {
if (cell.Value.ToString().Contains(searchValue)) {
cell.Selected = true;
}
}
}
}
これが役に立ちます。
ありません、これは動作しない。(私は –
、私はそれを実行したとき、私は作品を掲載コードをあなたのコードを試してみましたどのようなエラーあなたは何の結果は次に – JohnG
なっている。?をあなたはそれをデバッグする必要があります。検索値が一致し、セルが選択に設定されている場所にメッセージボックスを置く。メッセージボックスが表示され、セルが選択されていない場合、 –