根据从 DataGridView 中选择的值限制 NumericUpDown 值
Limit NumericUpDown Value depending on Value selected from DataGridView
如何限制可以输入 NumericUpDown
(nudqty) 的最大整数。当我使用向上向下箭头更改它时,我的代码有效,它限制了值,但当我键入它时却没有。请提出建议,如果在 NumericUpDown
中不可行,请告诉我,只需将其更改为 TextBox
。
private void dgv1_CellClick(object sender, DataGridViewCellEventArgs e)
{
lblqty.Text = dgv1.SelectedRows[0].Cells[5].Value.ToString();
nudqty.Maximum = Convert.ToDecimal(lblqty.Text);
}
将 DataGridView
的 SelectionMode
设置为 FullRowSelect
,然后将 SelectionChanged
event of DataGridView
. In the event after finding the value using CurrentRow
, reset the Value
of NumericUpDown
to 0 and set its Maximum
处理为提取的值:
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
int max = (int)this.dataGridView1.CurrentRow.Cells[5].Value;
this.numericUpDown1.Value = 0;
this.numericUpDown1.Maximum = max;
}
如何限制可以输入 NumericUpDown
(nudqty) 的最大整数。当我使用向上向下箭头更改它时,我的代码有效,它限制了值,但当我键入它时却没有。请提出建议,如果在 NumericUpDown
中不可行,请告诉我,只需将其更改为 TextBox
。
private void dgv1_CellClick(object sender, DataGridViewCellEventArgs e)
{
lblqty.Text = dgv1.SelectedRows[0].Cells[5].Value.ToString();
nudqty.Maximum = Convert.ToDecimal(lblqty.Text);
}
将 DataGridView
的 SelectionMode
设置为 FullRowSelect
,然后将 SelectionChanged
event of DataGridView
. In the event after finding the value using CurrentRow
, reset the Value
of NumericUpDown
to 0 and set its Maximum
处理为提取的值:
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
int max = (int)this.dataGridView1.CurrentRow.Cells[5].Value;
this.numericUpDown1.Value = 0;
this.numericUpDown1.Maximum = max;
}