Hi, I am new to c# and was wondering could someone help me. i am trying to valiate a cell in my datagrid view so that when a minus value is entered, i will get an error, i am unsure of how this is completed, i have tried a few things and it does not work, this is the latest thing i have tried

if (row.Cells[3].Value.ToString () >= -1)

Recommended Answers

All 2 Replies

I had a play around and came up with this, it may help you out:

if (Convert.ToInt16(dataGridView1.CurrentRow.Cells[0].Value.ToString()) < 0) {
                MessageBox.Show("Negative Number");

            }

Use int.Parse() method:

if (int.Parse(row.Cells[3].Value.ToString()) >= -1)
{
   //do work...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.