none
ComboBox bound to some data "loses" value on refresh

    Question

  • Hi,

    I ran into some trouble when I tried to use a custom control (ComboBox) with my own query behind. Whenever the screen is refreshed, it will loose its value.

    The database has a table with a self reference. (A Computer can have a Host which is of course also a Computer). Lightswitch directly build a solution but it (of course) offered me all computers to choose from. So I build a spcial Query that only returns all computers that can act as a Host which worked quite nice.

    To get the data binding, I just followed the description given at http://dotnettim.wordpress.com/2011/05/09/lightswitch-limiting-item-selections-using-a-combobox/ :

    • I added the query as datasource
    • I changed the control to a Custom Control and selected ComboBox
    • I added the code to the Activated Event of the Screen that binds the DataSource to the query inside the screen and to bind the SelectedItem.

    When I open the screen, the control is always empty. I can select a Host System and save the change. The data is changed. When I refresh the Screen, the ComboBox is empty again and LightSwitch wants to safe that as change. (Also when opening a data entry - the lightswitch app sets the value to empty and knows that as a change.)

    My Code inside Activated:

            partial void ServerDetails_Activated()
            {
                IContentItemProxy comboControl = this.FindControl("HostSystem");
                comboControl.SetBinding(System.Windows.Controls.ComboBox.ItemsSourceProperty, "Screen.AllHostSystems", System.Windows.Data.BindingMode.TwoWay);
                comboControl.SetBinding(System.Windows.Controls.ComboBox.SelectedItemProperty, "Screen.tbl_ServerDetail.Host_System", System.Windows.Data.BindingMode.TwoWay);
            }

    It would be great if someone could help me with this issue. Another point (which I will research afterwards and where I hope to find a solution on my own) is the "null" entry. At the moment the ComboBox does not offer me a blank entry on its own.

    Thank you in advance for your time and help. If you need any further information then do not hesitate to ask me.

    With kind regards,

    Konrad


    Tuesday, May 15, 2012 10:50 AM

Answers

  • I'm not that familiar with the ComboBox control. But that article seems incorrect to me. You most certainly can limit the choices available in an AutoCompleteBox. And I find that Me.AutoCompleteBoxName.SelectedItem = DesiredProperty works just fine to keep the value after a refresh.

    Have a look through this article and try using an AutoCompleteBox as she describes.

    Tuesday, May 15, 2012 12:17 PM

All replies

  • I'm not that familiar with the ComboBox control. But that article seems incorrect to me. You most certainly can limit the choices available in an AutoCompleteBox. And I find that Me.AutoCompleteBoxName.SelectedItem = DesiredProperty works just fine to keep the value after a refresh.

    Have a look through this article and try using an AutoCompleteBox as she describes.

    Tuesday, May 15, 2012 12:17 PM
  • Hi Kyle,

    thank you very much. That article was exactly what I was looking for! I completly missed that I can set the Choices of the Auto Complete Box.

    With kind regards,

    Konrad

    Tuesday, May 15, 2012 1:05 PM