locked
Hide a tab on a List and Details Screen RRS feed

  • Question

  • I have an List and Details screen with the Parent (FM_FundData) and two child tables shown as Tabs (FM_ClassData) and (FM_UnderlyingFundData).  I would like to only show (make visible) the tab for (FM_UnderlyingFundData) only in FM_FundData.FundStructure equals a specific string. 

    I have found could that will allow you to hide columns in the child data grid, but not the grid itself.  When I attemped I was not able to get to the correct control or control property to make this work.

    Is this possible?


    • Edited by bird0620 Wednesday, July 11, 2012 2:04 PM spelling
    Wednesday, July 11, 2012 2:03 PM

Answers

  • You do this in the screen's Created method:

    VB:

    Private Sub ScreenName_Created()
        Me.FindControl("ControlName").IsVisible = some expression returning true/false
    End Sub

    C#:

    private voidScreenName_Created()
    {
        this.FindControl("ControlName").IsVisible = false;
    }
    Don't forget to replace "ScreenName" & "ControlName" with the corrects names of your screen/control.

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    • Proposed as answer by babloo1436 Wednesday, July 11, 2012 4:24 PM
    • Marked as answer by bird0620 Thursday, July 12, 2012 6:24 PM
    Wednesday, July 11, 2012 2:42 PM
    Moderator
  • You're welcome!

    Yes, that's another common scenario (hiding tab/tabs depending on a value in a grid's SelectedItem), & I'm glad you were able to apply the information I gave you to it.

    I'd make two changes to your code though:

    Private Sub ActiveFunds_SelectionChanged()
        If (Me.ActiveFunds.SelectedItem Is Nothing) Then return
    
        Me.FindControl("FM_UnderlyingFundDatas").IsVisible _
            = ( Me.ActiveFunds.SelectedItem.FundStructure = "529")
    End Sub

    The first change makes sure that if the method is called, but the SelectedItem is not set, that it will just quietly exit, not throw a null exception error.

    The second change is just simplification. Personal taste I guess, but I like to show people that they have "options".


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    • Marked as answer by bird0620 Friday, July 13, 2012 12:25 PM
    Friday, July 13, 2012 12:38 AM
    Moderator
  • Sorry, I missed the alert email for this. I have so many threads marked to alert me, & sometimes when I don't have time to answer straight away, I forget to go back, & it slips through the cracks, as this one obviously did.

    A "double save" shouldn't be required. The only time I've heard of that happening is when a value has been entered in say a TextBox, but hasn't lost the focus when the Save button is clicked.

    It's a bug that I've seen Justin state that he thought was "fixed". I don't really have an answer for that one I'm afraid.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    • Marked as answer by bird0620 Wednesday, August 1, 2012 1:20 PM
    Wednesday, August 1, 2012 12:59 PM
    Moderator
  • Yann,

    Thanks for the reply, I did not mark as answered because there was one more peice that I did not include in my original post that took me a little while to figure out. 

    This did help as I did not know it was that simple to name the FindControl.  I thought you would have to set the Datagrid, find the control on the grid then hide.

    So the only thing I had to do was change the event you stated, for this to work for me I needed to have this on Selection Changed event.

    Here is the code I used and it seems to be working they way I need.

            Private Sub ActiveFunds_SelectionChanged()
                If Me.ActiveFunds.SelectedItem.FundStructure = "529" Then
                    Me.FindControl("FM_UnderlyingFundDatas").IsVisible = True
                Else
                    Me.FindControl("FM_UnderlyingFundDatas").IsVisible = False
                End If
            End Sub

    Active Funds is the query of MF_FundData (parent table) that I have used to build this screen.

    Thank you for your time, answer, and for leading me in the right direction.

    • Marked as answer by bird0620 Thursday, July 12, 2012 6:24 PM
    Thursday, July 12, 2012 6:24 PM

All replies

  • You do this in the screen's Created method:

    VB:

    Private Sub ScreenName_Created()
        Me.FindControl("ControlName").IsVisible = some expression returning true/false
    End Sub

    C#:

    private voidScreenName_Created()
    {
        this.FindControl("ControlName").IsVisible = false;
    }
    Don't forget to replace "ScreenName" & "ControlName" with the corrects names of your screen/control.

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    • Proposed as answer by babloo1436 Wednesday, July 11, 2012 4:24 PM
    • Marked as answer by bird0620 Thursday, July 12, 2012 6:24 PM
    Wednesday, July 11, 2012 2:42 PM
    Moderator
  • Yann,

    Thanks for the reply, I did not mark as answered because there was one more peice that I did not include in my original post that took me a little while to figure out. 

    This did help as I did not know it was that simple to name the FindControl.  I thought you would have to set the Datagrid, find the control on the grid then hide.

    So the only thing I had to do was change the event you stated, for this to work for me I needed to have this on Selection Changed event.

    Here is the code I used and it seems to be working they way I need.

            Private Sub ActiveFunds_SelectionChanged()
                If Me.ActiveFunds.SelectedItem.FundStructure = "529" Then
                    Me.FindControl("FM_UnderlyingFundDatas").IsVisible = True
                Else
                    Me.FindControl("FM_UnderlyingFundDatas").IsVisible = False
                End If
            End Sub

    Active Funds is the query of MF_FundData (parent table) that I have used to build this screen.

    Thank you for your time, answer, and for leading me in the right direction.

    • Marked as answer by bird0620 Thursday, July 12, 2012 6:24 PM
    Thursday, July 12, 2012 6:24 PM
  • You're welcome!

    Yes, that's another common scenario (hiding tab/tabs depending on a value in a grid's SelectedItem), & I'm glad you were able to apply the information I gave you to it.

    I'd make two changes to your code though:

    Private Sub ActiveFunds_SelectionChanged()
        If (Me.ActiveFunds.SelectedItem Is Nothing) Then return
    
        Me.FindControl("FM_UnderlyingFundDatas").IsVisible _
            = ( Me.ActiveFunds.SelectedItem.FundStructure = "529")
    End Sub

    The first change makes sure that if the method is called, but the SelectedItem is not set, that it will just quietly exit, not throw a null exception error.

    The second change is just simplification. Personal taste I guess, but I like to show people that they have "options".


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    • Marked as answer by bird0620 Friday, July 13, 2012 12:25 PM
    Friday, July 13, 2012 12:38 AM
    Moderator
  • Hi Yann,

    One more question on this.  If I modify my record to show/hide the detail tab. I notice that when I change a selection from the list the * comes up marking that I have changed the record and need to save.  However, I have to save twice for it to go away.  While I agree Selection_Changed, is the event I would like to have the hide/unhide happen, I am thinking I am missing something to avoid the double save, as this should be under a different event.  This code is on a List Deatils Screen and the only ithe code I have on the screen is on a Created event.

    Any thoughts?

    Thanks,

    Dan

    Tuesday, July 24, 2012 8:15 PM
  • Sorry, I missed the alert email for this. I have so many threads marked to alert me, & sometimes when I don't have time to answer straight away, I forget to go back, & it slips through the cracks, as this one obviously did.

    A "double save" shouldn't be required. The only time I've heard of that happening is when a value has been entered in say a TextBox, but hasn't lost the focus when the Save button is clicked.

    It's a bug that I've seen Justin state that he thought was "fixed". I don't really have an answer for that one I'm afraid.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    • Marked as answer by bird0620 Wednesday, August 1, 2012 1:20 PM
    Wednesday, August 1, 2012 12:59 PM
    Moderator