locked
Accessing AutoCompleteBox in code RRS feed

  • Question

  • Hi All,

       I have several screens where I am using AutoCompleteBoxes to populate cascaded details.

    I need to prepopulate these auto complete boxes with related data when a user logs in to the system. Is there a way I can access the LS auto complete box in code & set its selected Item property in code?

    got to do this somehow, else it would be annoying for a user to select the same details again n again..

     Here is how the screen looks..

    P.S. These AutoCompleteBoxes selected values are bound to screen queries to populate related data for next AutoCompleteBox

    Some how I will have to manage this too in my code.

    Any pointers are appreciated.

    Thanks & Regards


    Supreet
    Tuesday, May 31, 2011 1:08 PM

Answers

  • Hi Supreet,

    I do this initialisation in the screen's InitializeDataWorkspace method.

    VB:

            Private Sub ScreenName_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
                With Me.DataWorkspace.ApplicationData
                    Me.SelectedStatus = .Statuses_Single(0)
                    Me.SelectedGender = .Genders_Single(0)
                End With
            End Sub
    

    C#:

    private void ScreenName_InitializeDataWorkspace(System.Collections.Generic.List<Microsoft.LightSwitch.IDataService> saveChangesTo)

    {

    this.SelectedStatus = this.DataWorkspace.ApplicationData.Statuses_Single(0);

    this.SelectedGender = this.DataWorkspace.ApplicationData.Genders_Single(0);

    }

    Hope that helps,

    Yann

    • Marked as answer by Supreet tare Tuesday, May 31, 2011 2:03 PM
    Tuesday, May 31, 2011 1:28 PM
  • Hi Supreet,

    You could maybe set the underlying value of the property on which the AutoCompleteBox is bound using similar syntax to the article below.

    http://dotnettim.wordpress.com/2011/03/16/lightswitch-setting-combobox-values-in-code/

    Tim

     

    • Marked as answer by Supreet tare Tuesday, May 31, 2011 2:04 PM
    Tuesday, May 31, 2011 1:32 PM

All replies

  • Hi Supreet,

    I do this initialisation in the screen's InitializeDataWorkspace method.

    VB:

            Private Sub ScreenName_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
                With Me.DataWorkspace.ApplicationData
                    Me.SelectedStatus = .Statuses_Single(0)
                    Me.SelectedGender = .Genders_Single(0)
                End With
            End Sub
    

    C#:

    private void ScreenName_InitializeDataWorkspace(System.Collections.Generic.List<Microsoft.LightSwitch.IDataService> saveChangesTo)

    {

    this.SelectedStatus = this.DataWorkspace.ApplicationData.Statuses_Single(0);

    this.SelectedGender = this.DataWorkspace.ApplicationData.Genders_Single(0);

    }

    Hope that helps,

    Yann

    • Marked as answer by Supreet tare Tuesday, May 31, 2011 2:03 PM
    Tuesday, May 31, 2011 1:28 PM
  • Hi Supreet,

    You could maybe set the underlying value of the property on which the AutoCompleteBox is bound using similar syntax to the article below.

    http://dotnettim.wordpress.com/2011/03/16/lightswitch-setting-combobox-values-in-code/

    Tim

     

    • Marked as answer by Supreet tare Tuesday, May 31, 2011 2:04 PM
    Tuesday, May 31, 2011 1:32 PM
  • Hi Yann, Tim

       Both of you have suggested the same thing, God knows why I din't think of it, it was pretty straight forward. :)

    May be for past couple of weeks I am using custom control for almost every thing & that has changed my mindset from looking at Simple things to find more complex solutions :(

     

    It works like a charm.

    Thanks a ton, you saved me a lot of efforts, I was litrally thinking of using Silverlight Combo Box instead of all my Auto Populate boxes. It was a weired thought, at least now i can say that :D

    Thanks again 


    Supreet
    • Marked as answer by Supreet tare Tuesday, May 31, 2011 2:03 PM
    • Unmarked as answer by Supreet tare Tuesday, May 31, 2011 2:04 PM
    Tuesday, May 31, 2011 2:03 PM
  • Hi Tim,

       I never saw your blog post before.. Its awesome :)

    I think of writing LS blogs but just couldn't find time. Was busy learning my self :)

    Anyways great work. It really helps.

    Thanks 


    Supreet
    Tuesday, May 31, 2011 2:09 PM