binidngNewbie
binidngNewbie

Reputation: 1

binding textbox with trackbar and with field in class

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

Upvotes: 0

Views: 2048

Answers (1)

DV8DUG
DV8DUG

Reputation: 247

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 >= trackBar1.Minimum && yourSanitized <= trackBar1.Maximum);
    {
         trackBar1.Value = int.Parse(yourSanitized.ToString());
    }
}

Upvotes: 1

Related Questions