locked
Can I change isvisible while a screen is open? RRS feed

  • Question

  • I have a somewhat complex screen that is used for 3 different types of orders.  The 3 order types all share most of the fields in common but there are a few fileds that are unique to each order type.  On a new entry I would like to display all the common fileds but hide the unique fields until the user first selects the type from a list.  Once the selction is made (from a drop-down) I want the unique fields associated with the order type to become visible.  

    I have already set each of the unique fields to notvisible in the ScreenCreated method... my question is how do I now prgrammatically change the novisible to isvisible based on the selection of the order type (basically a simple 1, 2 or 3).

    Thanks 

       
    Tuesday, January 15, 2013 5:08 PM

All replies

  • You use "FindControl" to reference the controls.

    I use the following code in a simple wizard with "Next" and "Previous" buttons:

    this.FindControl("Tab_SelectDataSet").IsVisible = false;
    this.FindControl("Tab_CashFlowBarChartCFOnly").IsVisible = true;
    this.FindControl("Tab_CashFlowBarChartCFOnly").Focus();

    Mark

    • Proposed as answer by Xpert360 Tuesday, January 15, 2013 6:06 PM
    Tuesday, January 15, 2013 5:25 PM
  • Yes... I already use the FindControl when I initailly set the screen... what I am looking for is how to then make the control visible once a type is selected.   What method do I put the code in? 
    Tuesday, January 15, 2013 7:36 PM
  • You could use a Collection SelectionChanged event.

    Or . . . any other event control.

    This is a common practice.  You can also do the same thing to switch on and off property editing.

    A Group (RowLayout, etc.) can be made Visible or non-Visible.   Very powerful GUI options for a RAD web screen designer.


    Garth Henderson - Vanguard Business Technology

    Tuesday, January 15, 2013 9:13 PM
  • Great... I'll can't wait to see this work.

    Please forgive my lack of knowledge as I have yet to fully comprehend the timing of events in VB.   I would like to tie it in with the selection from a drop-down box.  I have a field in the order header named type and it has a choice list of 3 types (which I set in the entity designer).  As soon as the user selects the order type from the list is when I want to change applicable fields to Visible.  Would I still code it in any event control or is one preferred over another? 

    Thanks for your help.

    Tuesday, January 15, 2013 9:41 PM
  • Hiya Jyuma,

    I don't know VB, so I'll bow out of the conversation.


    Garth Henderson - Vanguard Business Technology

    Tuesday, January 15, 2013 10:21 PM
  • Please... someone, I'm at a dead stop here.

    I'm trying to find where to put the code to change the IsVisible to true if an order type 2 is selected from the drop-down on the screen.

    I found the fieldname_changed() method but when I attempt to enter the VB code Me.FindControl("mycontrolname").IsVisible = True  I get an error that says Me.FindControl) is not a member of blah blah blah.

    Any idea where am I supposed to put the code to change the IsVisible to True.  

    Thanks.

    Wednesday, January 16, 2013 1:46 AM
  • Also... I found what I think is a solution but I get compiler errors about Dispatchers and property changed.

    I found a post where it says to use an import/using statement for "System.ComponentModel" and "Microsoft.Lightswitch.threading" but being the noob that I am I have no idea where to put them.

    My fondest wish is that there was a classification we could give ourselves relative to experience level so you pro's would know when your responding to a guy that knows very little and many of the terms that get used may make perfect sense to people with experience but have no meaning to us beginners.  Not complaining... just making an observation that many times the answers come across like a foreign langauge... no pun intended.  :).

    Thanks 

    Wednesday, January 16, 2013 3:00 AM
  • Ed, seeing as you want to react to a change in a property on a screen (as opposed to a property in a table), my preferred method of doing this is to implement INotifyPropertyChanged.

    To do this, you simply add a line in the screen's Created method:

    Private Sub TeamMemberDetail_Created()
        AddHandler DirectCast(this, INotifyPropertyChanged).PropertyChanged _
            , AddressOf PropertyChanged)
    End Sub

    Then add a private method to the screen's code:

    Private Sub PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
        Select Case e.PropertyName
            Case "YourPropertyName"
                'use FindControl here to set visibility of properties here
    
            Case "SomeOtherPropertyName"
                'do something else
        End Select
    End Sub

    This private method can handle the changes in one property, or multiple properties, all in one code method.

    Note: You can use If/Then instead of Select Case, but again Select Case is my preference.

    Does that help?


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

    Wednesday, January 16, 2013 3:38 AM
    Moderator
  • @Yann...  as always I am in your debt but regrettably my lack of experience is showing again.  hahaha.

    Two questions...  What is TeamMemberDetail?

    And does this method eliminate the need for the two Import/Using statements you mentioned in past posts? 

    I got so frustrated that I took a hint I found in your book and put several buttons on the page.  At least that way when I entered the execute code for the method the compiler liked the command FindControl.  When I tried to use that same command on the fieldname_Changed (writeCode drop-down) the compiler threw errors. 

    It's after midnight here and I've been at this since about 5:00 am this morning so I'll try the changes you suggested in the morning when I can see the keys.

    Thanks again.

    Ed

     

    Wednesday, January 16, 2013 5:14 AM
  • I tried the code and the compiler throws 4 errors:

    PropertyChangedEvent Args is not defined.

    FindControl is not a member of LightSwitchApplication.Workorder.

    And in the CreatNewWorkorder_created()  there are two errors...

    AddHandler this is not declared

    PropertyChanged is not declared.

    Can I assume the two import/using statements are required and if so please let me know the exact format and precisely where they go.  Believe it or not, I really don't know what "in your screen code" means.  I see code associated with the screen all over the place. :(  

    Thanks

    Wednesday, January 16, 2013 6:34 PM
  • My apologies!

    I'm afraid I took it for granted that you'd know how to handle adding import statements when they're not there. I shouldn't ass-u-me, sorry.

    In any class where you're implementing INotifyPropertyChanged, you'll need this statement at the top of the file:

    Imports System.ComponentModel

    That import statement will also take care of PropertyChangedEventArgs as well (note, in your text you had a space between PropertyChangedEvent & Args, which shouldn't be there, it's all one word.

    TeamMemberDetail was the name of the screen I coped the code from, so it should have been YourScreenName_Created.

    You can only use FindControl in the code of a screen, you can't use it in a table's code, which it looks like you might be trying to do.

    I don't know why AddHandler is "undefined", it's a VB statement that's part of the language itself. It's probably complaining about the PropertyChanged method due to the earlier error regarding PropertyChangedEventArgs (once that's fixed, this error should go away).

    By "in the screen's code", I meant in the same class that the screen's Created method is. Each screen has one code file associated with it. You can get there by clicking "Write Code" when you're in the screen designer. Just put the PropertyChanged method code in between any other methods that you see in that file (directly under the Created method if you like).

    So to show all of that in one example:

    Imports System.ComponentModel
    
    Namespace LightSwitchApplication
    
        Public Class YourScreenName
    
            Private Sub YourScreenName_Created()
                AddHandler DirectCast(Me.YourScreensPropertyName) AddressOf PropertyChanged
            End Sub
    
            Private Sub PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
    
                Select Case e.PropertyName
                    Case "YourPropertyName"
                        'use FindControl here to set visibility of properties 
    
                    Case "SomeOtherPropertyName"
                        'do something else        
                End Select
            End Sub
    
        End Class
    
    End Namespace

    I hope that helps explain it better? If not, please don't hesitate to ask me to clarify further.


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

    Thursday, January 17, 2013 12:41 AM
    Moderator
  • OK... I'm going nuts with this problem.

    I use the Write Code drop-down and select the CreateNewWorkorder_Created method.

    I then add Yann's code directly after the CreateNewWORKORDER_Created()

    Here's the code...

    Private Sub CreateNewWORKORDER_Created()

    Dispatchers.Main.BeginInvoke(

    Sub()

    AddHandler DirectCast(Me.EntityProperty,INotifyPropertyChanged).PropertyChanged, AddressOf PropertyChanged

    End Sub

    )

    ' Hide fields that don’t get data on a new workorder

    Me.FindControl("totalhrs").IsVisible = False

    Me.FindControl("upddate").IsVisible = False

    Me.FindControl("StatusNote").IsVisible = False

    Me.FindControl("CompleteDate").IsVisible = False

    Me.FindControl("Status").IsVisible = False

    Me.FindControl("Invoiced").IsVisible = False

    Me.FindControl("InvoicedDate").IsVisible = False

    End Sub

    Intellisense highlights the word Dispatchers (in dispatchers.main) and displays the message 'Dispatchers' is not declared. It may be inaccessible due to its protection level.

    I'm stuck! :(

    Ed




    • Edited by Jyuma1 Thursday, January 17, 2013 1:24 AM
    Thursday, January 17, 2013 1:19 AM
  • I missed adding the dispatcher call (if I hadn't I would have added the import for it to my example), sorry.

    Just add this import at the top of the file:

    Imports Microsoft.LightSwitch.Threading

    I actually use an extension method for adding property changed handlers, that I created ages ago, so when I dove into it to find the AddHandler line, I didn't notice the BeginInvoke call around it.

    More haste required, less speed I think. :-(


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

    Thursday, January 17, 2013 1:51 AM
    Moderator
  • Sorry Yann.... you must have posted while I was composing my "OK, I'm going nuts with this problem" post.

    I greatly appreciate all the help you give.

    bTw... I have this book written by a guy in Australia (who looks just like you) so anytime you think it would be helpful for me to review a certain chapter or page just let me know.  It might save you some typing.  :)    

    Thursday, January 17, 2013 3:15 AM
  • You're very welcome Ed!

    I hope your problem is sorted out now?

    Feel free to write a review on anything about LightSwitch, or our book, that you like. I'd be happy to post it to LightSwitch Central for you. Or I can set up a blog for you if you want, where you can share your experiences from a "newcomer's" perspective. I don't get as much time as I'd like to blog about stuff.

    A review on Amazon would probably be very helpful for people, if you feel so inclined. I could then add a link to it on the LightSwitch Central Books page.

    I'm also happy to post any review you might write on any book written by one of the other authors. LightSwitch Central exists to provide information about LightSwitch to the community, it's not there for my self-promotion (I just happen to be the co-author of one of the books).


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

    Thursday, January 17, 2013 4:18 AM
    Moderator