h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Compare Two Cell Values in Datagridview using C#.Net

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
if (e.ColumnIndex == 2)
{
 int minValue = Convert.ToInt32(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["MinValue"].Value.ToString()); int maxValue = Convert.ToInt32(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["MaxValue"].Value.ToString()); bool chkValue = compareTwoCellValues(minValue, maxValue);
if (chkValue)
{
 dataGridView1.AllowUserToAddRows = false; dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["MaxValue"].Selected = true; chkValue = false;
}
 else
 {
 dataGridView1.AllowUserToAddRows = true; chkValue = false;
 }
}
}
bool statusofCompareValue;
bool compareTwoCellValues(int MinValue, int MaxValue)
{
 if (MinValue > MaxValue)
 {
 MessageBox.Show("Please enter greater than value"); statusofCompareValue = true;
 }
 else
 {
statusofCompareValue = false;
}
 return statusofCompareValue;
 }