我在文本框中有一个从 SQL 数据库检索的数值,同时我有一些未绑定的 GridView 行。现在我想将文本框值与 datagridview 单元格值进行比较。
if(int.Parse(textBox.Text) > dataGridView.Rows[0].Cells[0].Value)
{
// Here you do what you want to do
// when the textbox value is greater than the grid cell value.
}
此代码将检查第一行的第一个单元格。如果您想检查另一个单元格,则应将行索引从
Rows[0]
更改为 Rows[/* row index */]
,将列索引从 Cells[0]
更改为 Cells[/* cell index /*]
。