简体   繁体   中英

how to check if the textbox int value is greater than datagridview CurrentRow int value

how to check if the textbox int value is greater than datagridview CurrentRow int value.

What I have 

            if (int.Parse(txtAddQty.Text) >= dtgList.CurrentRow.Cells[5].Value)
            {
                // Here what I want to do
                
            }

but ended with error Operator '>=' cannot be applied to operands of type 'int' and 'object'

anyone with the solution. thank you

If you are certain of the Cell's value type

if (int.Parse(txtAddQty.Text) >= (int)dtgList.CurrentRow.Cells[5].Value)
{
     // Here what I want to do
                
}

Otherwise, you'll be safer:

string cellValue = dtgList.CurrentRow.Cells[5].Value.ToString();
int intValue;
bool isInt = int.TryParse(cellValue, out intValue);
if (int.Parse(txtAddQty.Text) >= intValue && isInt)
{
     // Here what I want to do
                
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM