我的窗体中有两个DataGridViewTextbox列。我想比较一个文本框与另一个文本框的值。在C#中验证DataGridView文本框单元格?
看到的是有提供信息的图像...,
这是在蓝色它们是只读的......我想,我得到的答案
我的窗体中有两个DataGridViewTextbox列。我想比较一个文本框与另一个文本框的值。在C#中验证DataGridView文本框单元格?
看到的是有提供信息的图像...,
这是在蓝色它们是只读的......我想,我得到的答案
试试这个
if (DataGridView.Rows[0].Cells["Quantity"].Value > DataGridView.Rows[0].Cells["other"].Value)
{
//do something
}
嗨@Amir我不是问单元值,发出的数量总和不大于需要的消耗品的值 – Anjali
附上您的网格CellValidating
事件:
private void GridCellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == ColQuantityIssues.Index) // Quantity Issues TextBox value has changed
{
int quantityIssued = 0;
if (!Int32.TryParse(e.FormattedValue.ToString(), out quantityRequired)) //value is not a valid number
{
e.Cancel = true;
}
int quantityRequired = Int32.Parse(dgv.Rows[e.RowIndex].Cells[ColQuantityRequired.Index].Value.ToString());
if (quantityRequired < quantityIssued)
{
e.Cancel = true;
}
}
}
事件参数公顷s FormattedValue
这是用户输入的新值。只要值无效,将e.Cancel
设置为true将不允许用户离开当前单元格。
您可以更改我的ColQuantityIssues和ColQuantityRequired以按名称访问它们(即dgv.Rows [e.RowIndex] .Cells [“Required”]),但应该可以。
你有什么尝试吗? –
老板,我没有得到任何想法......,我在想 – Anjali
那么你需要比较什么?您是否需要比较所需数量与数量问题? –