CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    May 2011
    Posts
    7

    WPF Combo Box doesn't rollup until the event is processed.

    I have a small program which has a combobox and a text box on it.

    In the combo box selection changed event, i have something like this

    private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    System.Threading.Thread.Sleep(10000);
    textBox1.Text = "Something";

    }

    When ever i select something from the combox box, it waits 10sec and displays "Something" in textBox1. But the problem here is until 10sec, the combobox stay open, then displays text and then rollup. That means it is waiting until selectionchanged event to completed to rollup.

    How can i make the combobox rollup(or close) ones a value is selected.

    I am attaching a picture, which shows the rolldown of combobox(If what i said above is not clear)

    Thank You for any help!!!!
    Attached Images Attached Images  

  2. #2
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: WPF Combo Box doesn't rollup until the event is processed.

    What is the reason to wait for 10secs?
    Regards,
    MMH
    Rate my post if you find it usefull.

  3. #3
    Join Date
    May 2011
    Posts
    7

    Resolved Re: WPF Combo Box doesn't rollup until the event is processed.

    The reason to wait 10 seconds is to show the rolldown of the combobox. In actual i have lot of code to process inside the slectionchanged event which takes about 50seconds. To mimic that behaviour i just had a 10sec lag in there.

    Thank You! I figured out how to do it.

    Create seperate thread for 10 second wait and fill TextBox after that.

    private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(ExecuteThread));
    th.Start();
    }

    private void ExecuteThread()
    {
    System.Threading.Thread.Sleep(10000);
    this.Dispatcher.Invoke(new Action(delegate()
    {
    textBox1.Text = "Something";
    })
    );
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured