Question

I am c# silverlight5 beginner and i have a situation that i have to created a combo box dynamically using c# and kept items in it. But the problem now when i run it run properly showing the last value by default but when i select the another value it don't update the that value in the text box near by because it is not working dynamically.

I guess i need to add some selection changed or some other event using c#. But i dont know how to do that. Please note that i have created this combo box using c# only.

How to change the value in correspondng selection to the combobox value ?(just using c#)

Était-ce utile?

La solution 2

At last i have done it using SelectionChanged and creating SelectionChangedEventHandler. The code is as below (may be useful for some future user):

cb.SelectionChanged += new SelectionChangedEventHandler(comboBox1_SelectionChanged); in converter() function and outside converter function :

 void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        txtblk2.Text = cb.SelectedValue.ToString() + " millions";
    }

Autres conseils

Just when creating the combobox, create also the binding in c#, then it will update the textbox automatically without the need for any events or additional code.

  var binding = new Binding("Text");
  binding.Source = cb;
  binding.StringFormat = "{0} millions";
  txtblk2.SetBinding(TextBlock.TextProperty, binding);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top