如何在c#中找出文本框值大于datagridview单元格值?

问题描述 投票:0回答:1

我在文本框中有一个从 SQL 数据库检索的数值,同时我有一些未绑定的 GridView 行。现在我想将文本框值与 datagridview 单元格值进行比较。

c# datagridview
1个回答
0
投票
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 /*]

© www.soinside.com 2019 - 2024. All rights reserved.