locked
Lookup List Column Selection RRS feed

  • Question

  • I Have following to tables

    Products

                    ID

                    Name

                    Price

                    Qty

                    Category

     

    Group

                    ID

                    GroupName

    Category

                    ID

                    Group

                    CategoryName

                    FullCategory (This is computed Property which show like this “System/Motherboard” etc.

     

    In screen of Products I want to show Category’s Filed FullCategory.

     

    Please guide me how I do that.

     

    Thank You

     

     

    Saturday, August 15, 2015 2:54 PM

Answers

  • Hi Javed,Yusuf,

    I find another way that bind query to the ComboBox. Please try with below steps.

    1. Create a query for the Category table which is get all categories from table.
    2. On Product screen, modify the Category as custom control.
    3. Select the custom control of Category and in the Properties window click the "Change…" behind the "Custom Control". Then choose ComboBox.
    4. Add following code in the _InitializeDataWorkspace method which is set ItemSource for ComboBox and set the value of Category after you select Category.
    partial void CreateNewProduct_InitializeDataWorkspace(List<IDataService> saveChangesTo)
    {
    	  this.ProductProperty = new Product();
    	  this.FindControl("Category").ControlAvailable += CreateNewProduct_ControlAvailable;
    }
    	
    ComboBox c;
    void CreateNewProduct_ControlAvailable(object sender, ControlAvailableEventArgs e)
    {
    	if (e.Control is ComboBox)
    	{
    	    c = (ComboBox)e.Control;
    	    c.SelectionChanged += c_SelectionChanged;
    	    c.ItemsSource = this.GetAllCategories;
    	    c.SelectedValuePath = "FullCategory";
    	    c.DisplayMemberPath = "FullCategory";
    	}
    }
    	
    void c_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    	ProductProperty.Category = ((Category)c.SelectedItem).FullCategory;
    }
    

    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Friday, August 28, 2015 2:47 AM
    • Marked as answer by Angie Xu Monday, August 31, 2015 1:18 AM
    Wednesday, August 19, 2015 8:40 AM
    Moderator

All replies

  • Hi Javed.Yusuf,

    Please try with custom control. You can create a combobox that binding with Category table, and set its DisplayMemberPath as FullCategory. Then use this custom control on your Products screen. About how to Bind to a custom control combobox, please refer to below thread.
    http://lightswitchhelpwebsite.com/Forum/tabid/63/aft/170/Default.aspx
     
    Best Regards,
    Weiwei

    Monday, August 17, 2015 9:04 AM
    Moderator
  • Thank for your reply

    i follow this tutorial http://lightswitchhelpwebsite.com/Forum/tabid/63/aft/170/Default.aspcombobox shows but not category data shows in this control.

    Tuesday, August 18, 2015 10:50 AM
  • Hi Javed,Yusuf,

    I find another way that bind query to the ComboBox. Please try with below steps.

    1. Create a query for the Category table which is get all categories from table.
    2. On Product screen, modify the Category as custom control.
    3. Select the custom control of Category and in the Properties window click the "Change…" behind the "Custom Control". Then choose ComboBox.
    4. Add following code in the _InitializeDataWorkspace method which is set ItemSource for ComboBox and set the value of Category after you select Category.
    partial void CreateNewProduct_InitializeDataWorkspace(List<IDataService> saveChangesTo)
    {
    	  this.ProductProperty = new Product();
    	  this.FindControl("Category").ControlAvailable += CreateNewProduct_ControlAvailable;
    }
    	
    ComboBox c;
    void CreateNewProduct_ControlAvailable(object sender, ControlAvailableEventArgs e)
    {
    	if (e.Control is ComboBox)
    	{
    	    c = (ComboBox)e.Control;
    	    c.SelectionChanged += c_SelectionChanged;
    	    c.ItemsSource = this.GetAllCategories;
    	    c.SelectedValuePath = "FullCategory";
    	    c.DisplayMemberPath = "FullCategory";
    	}
    }
    	
    void c_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    	ProductProperty.Category = ((Category)c.SelectedItem).FullCategory;
    }
    

    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Friday, August 28, 2015 2:47 AM
    • Marked as answer by Angie Xu Monday, August 31, 2015 1:18 AM
    Wednesday, August 19, 2015 8:40 AM
    Moderator
  • Thank you for your kind reply, sir i am using vb.net. please tell me how to do this in vb.net or just i convert this code to vb.net work fine? also i tell you i am using Editable Grid Screen Template.

    • Edited by Javed.Yusuf Thursday, August 20, 2015 10:53 AM
    Thursday, August 20, 2015 10:27 AM
  • Hi Javed.Yusuf,

    I'm not familiar with VB, I just can do some simple transformations. The code convert to VB as below showing. And if you are using Editable Grid Screen Template, there some difference with below code. The control of Category in DataGrid is a list. So please get the column template which display categories in the DataGrid and then register ControlAvailable event for ComboBox in column template.

    Public Class EditableProductsGrid
            Dim ProductProperty As Product
            Private Sub EditableProductsGrid_InitializeDataWorkspace(saveChangesTo As List(Of Microsoft.LightSwitch.IDataService))
                ' Write your code here.
                AddHandler Me.FindControl("Category").ControlAvailable, AddressOf CreateNewProduct_ControlAvailable
            End Sub
    
            Private c As ComboBox
    
            Private Sub CreateNewProduct_ControlAvailable(ByVal sender As Object, ByVal e As ControlAvailableEventArgs)
                If (TypeOf e.Control Is ComboBox) Then
                    c = CType(e.Control, ComboBox)
                    AddHandler c.SelectionChanged, AddressOf c_SelectionChanged
                    c.ItemsSource = Me.DataWorkspace.ApplicationData.Categories
                    c.SelectedValuePath = "FullCategory"
                    c.DisplayMemberPath = "FullCategory"
                End If
            End Sub
    
            Private Sub c_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
                ProductProperty.Category = CType(c.SelectedItem, Category).FullCategory
            End Sub
        End Class
    


    Best Regards,
    Weiwei

    Monday, August 24, 2015 1:06 AM
    Moderator