views:

33

answers:

1

Hi.

I am trying something simple but struggling to get a simple solution, just not seeing it hehe.

I have a number: “150” witch can be split in any number of segments when the user enters the segment amount in a textbox; a items control gets populated with textboxes showing the segment sizes. This works.

I want to be able to edit a segment size and then calculate the remaining sizes left to show on the other segment textboxes, but cant figure out how to do it. If someone can just point me in a direction tanks.

To show what I mean i have included a link to the project vs2010 here (49kb)

A: 

I'm unsure whether you're having trouble editing an existing segment size or whether its the re-calculation that you're having trouble with.

But one method might be to subscribe to the KeyDown event on the textbox, then check for the return key. then you could recalculate the segments , iterate the collection and update each item with the new segment.

private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Return)
    {
        TextBox textbox = sender as TextBox;
        int newSegments;
        if (int.TryParse(textbox.Text, out newSegments))
        {
            //recalculate the segments
            //iterate the collection
            //update the segments
        }
    }
} 
Val