简体   繁体   English

限制NumericUpDown值,具体取决于从DataGridView中选择的值

[英]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找到值之后,将NumericUpDownValue重置为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM