我有一个网格,它有 6 列(项目名称、最小数量、最大数量、最大数量、最大数量、折扣)。
要求
当我选择min Quantity时,max Quantity 列将禁用并且其值变为零,当我选择min amount 时,max amout 列将禁用,反之亦然。当我输入数量的最小值时,网格行包含第一行的最大值。
/* You can use grid's cell validating event.
ColMinimumQuantity, ColMaximumQuantity, ColMinimumAmount, ColMaximumAmount are grid's column name
you can set them in Grid Properties. */
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (dataGridView1.CurrentCell.OwningColumn.Name.ToUpper().ToString() == "ColMaximumQuantity")
{
dataGridView1.CurrentRow.Cells["ColMinimumQuantity"].Value = "0";
dataGridView1.CurrentRow.Cells["ColMaximummQuantity"].ReadOnly = false;
dataGridView1.CurrentRow.Cells["ColMinimummQuantity"].ReadOnly = true;
}
if (dataGridView1.CurrentCell.OwningColumn.Name.ToUpper().ToString() == "ColMaximumAmount")
{
dataGridView1.CurrentRow.Cells["ColMinimumAmount"].Value = "0";
dataGridView1.CurrentRow.Cells["ColMaximummQuantity"].ReadOnly = false;
dataGridView1.CurrentRow.Cells["ColMinimummQuantity"].ReadOnly = true;
}
if (dataGridView1.CurrentCell.OwningColumn.Name.ToUpper().ToString() == "ColMinimumAmount")
{
dataGridView1.CurrentRow.Cells["ColMaximumAmount"].Value = "0";
dataGridView1.CurrentRow.Cells["ColMiniimumAmount"].ReadOnly = false;
dataGridView1.CurrentRow.Cells["ColMaximumAmount"].ReadOnly = true;
}
}
您可以使用网格的单元格验证事件。
ColMinimumQuantity, ColMaximumQuantity, ColMinimumAmount, ColMaximumAmount 是网格的列名,您可以在网格属性中设置它们。