0
votes

I have problem with binding textbox with trackbar and with a property in class. I bind a textbox.text property to field

`Progress`

in my object. Next I managed to bound property Value from trackbar to TextBox Text property. If I change value in trackbar the textbox Text property also changes. However if I change textbox.text property, the trackbar won't update. How can I force the trackbar to update itself if I changed text and the textbox to update itselft if I change a trackbar value

1
C# - winforms. I was trying to do this bymyself however I always get an error that given property has benn bound already - or sth similar - binidngNewbie

1 Answers

1
votes

Sanitize your data before throwing it back at your trackbar...

  private void trackBar1_Scroll(object sender, EventArgs e)
        {
            yourTextBox.Text = "" + trackBar1.Value;
        }
  private void yourTextBox_TextChanged(object sender, EventArgs e)
        {
            var yourSanitized = int.Parse(yourTextBox.Text);
            if (yourSanitized >= 1 && yourSanitized <= 100);// min and max value
            {
                trackBar1.Value = int.Parse(yourSanitized.ToString());
            }
       }