question

MajeedPurseyedmahdi-3716 avatar image
0 Votes"
MajeedPurseyedmahdi-3716 asked DanielZhang-MSFT commented

How to start the number from 1 by clicking the add button inside the text box?

111932-capture.jpg


windows-forms
capture.jpg (36.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe handle the Click event of "+" button in this manner:

textBox.Text = "1";


0 Votes 0 ·
DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered DanielZhang-MSFT commented

Hi MajeedPurseyedmahdi-3716,
Do you want to achieve the following situation?

 int Number = 0;
 private void button1_Click(object sender, EventArgs e)
 {
     Number ++;
     textBox1.Text = Number.ToString();
 }

112011-76.gif
If not, please explain in detail.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



76.gif (30.9 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Display row number from database to text box in C #.entity framwork code first

0 Votes 0 ·
DanielZhang-MSFT avatar image DanielZhang-MSFT MajeedPurseyedmahdi-3716 ·

Hi @MajeedPurseyedmahdi-3716,
Without more information and code, we can’t determine where you encountered the problem.
And there are some examples on how to use Entity Framework to obtain line numbers through LINQ in the following links, hope to help you.
Get Row Index in a list by using entity framework
Get record's row number using Linq
How to get index using LINQ? [duplicate
Best Regards,
Daniel Zhang


0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

You could use a custom TextBox

 public class TextBoxUpDown : TextBox
 {
     public TextBoxUpDown()
     {
         Text = "0";
     }
     private int _value;
        
     public void Increment()
     {
         _value += 1;
         Text = _value.ToString();
     }
    
     public void Decrement()
     {
         _value -= 1;
         Text = _value.ToString();
     }
    
     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
     public int Value => _value;
 }


Usage

 private void IncrementButton_Click(object sender, EventArgs e)
 {
     textBoxUpDown1.Increment();
 }
    
 private void DecrementButton_Click(object sender, EventArgs e)
 {
     textBoxUpDown1.Decrement();
 }
    
 private void ValueButton_Click(object sender, EventArgs e)
 {
     MessageBox.Show(textBoxUpDown1.Value.ToString());
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.