[英]Limit NumericUpDown Value depending on Value selected from DataGridView
How can I limit max int that can be entered into my NumericUpDown
(nudqty). 如何限制可以输入到
NumericUpDown
(nudqty)中的max int。 my code works it limits the value when I change it using up down arrows, but when I type it's not. 我的代码有效,当我使用向下箭头更改它时会限制该值,但是当我键入时却没有。 suggestions please and tell me if it's not possible in
NumericUpDown
and just change it to TextBox
. 请提出建议,告诉我在
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);
}
Set SelectionMode
of DataGridView
to FullRowSelect
and then handle SelectionChanged
event of DataGridView
. 将
DataGridView
SelectionMode
设置为FullRowSelect
,然后处理DataGridView
SelectionChanged
事件。 In the event after finding the value using CurrentRow
, reset the Value
of NumericUpDown
to 0 and set its Maximum
to the extracted value: 在使用
CurrentRow
找到值之后,将NumericUpDown
的Value
重置为0并将其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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.