locked
dynamically change field visibility or disable RRS feed

  • Question

  • Hello, I need a sort of dynamic data entry flow process where selecting one field changes what other fields are available for input.

    So for example if field 1 is selected as value A, fields 2 and 3 are now enabled for entry, but if it was selected as value B, those two fields are not available and field 4 is available for entry.  I can either do this with dynamic visibility or enable/disable.

    Is this possible?  thanks

    Friday, August 5, 2011 11:51 PM

Answers

  • Wow, I just answered this another post, lol. I need to make some posts on my blog! :-)

    I'll see if I can find the other forum post, but basically the technique relies on INotifyPropertyChanged (or you could also use LostFocus, but that involkves more work) & making use of:

    VB:

    Me.FindControl("YourControlName").IsVisible = true/false
    
    'or
    
    Me.FindControl("YourControlName").IsEnabled = true/false
    
    'or
    
    Me.FindControl("YourControlName").IsReadOnly = true/false
    

    C#:

    this.FindControl("YourControlName").IsVisible = true/false;
    
    //or
    
    this.FindControl("YourControlName").IsEnabled = true/false;
    
    //or
    
    this.FindControl("YourControlName").IsReadOnly = true/false;
    

     


    Yann

    (plus ça change, plus c'est la même chose!)

    Saturday, August 6, 2011 4:52 AM
    Moderator

All replies

  • Wow, I just answered this another post, lol. I need to make some posts on my blog! :-)

    I'll see if I can find the other forum post, but basically the technique relies on INotifyPropertyChanged (or you could also use LostFocus, but that involkves more work) & making use of:

    VB:

    Me.FindControl("YourControlName").IsVisible = true/false
    
    'or
    
    Me.FindControl("YourControlName").IsEnabled = true/false
    
    'or
    
    Me.FindControl("YourControlName").IsReadOnly = true/false
    

    C#:

    this.FindControl("YourControlName").IsVisible = true/false;
    
    //or
    
    this.FindControl("YourControlName").IsEnabled = true/false;
    
    //or
    
    this.FindControl("YourControlName").IsReadOnly = true/false;
    

     


    Yann

    (plus ça change, plus c'est la même chose!)

    Saturday, August 6, 2011 4:52 AM
    Moderator
  • Found the post: 

    How to programmatically hide and show fields


    Yann

    (plus ça change, plus c'est la même chose!)

    Saturday, August 6, 2011 4:54 AM
    Moderator
  • thanks alot! havent had a chance to test this yet but this looks like exactly what i need.
    Monday, August 8, 2011 5:58 PM
  • You're welcome.

    Yann

    (plus ça change, plus c'est la même chose!)

    Tuesday, August 9, 2011 12:49 AM
    Moderator
  • How to do that in a column inside a grid
    Thursday, August 18, 2011 10:40 AM
  • You can use the FindControlInCollection method, passing the column name and the row of the grid.

    The help text shows that you have to iterate through each row of the grid to do this for the whole column. EG

    Private Sub FindControlInList()
       Dim index As Integer = 0
     
       For Each cust As Customer In Customers
     
         If cust.CompanyName = "Great Lakes Food Market" Then
           With FindControlInCollection("CompanyName", Customers(index))
             .IsVisible = False
             .IsReadOnly = True
           End With
     
         End If
         index = index + 1
       Next
     End Sub
    
    

    I'm sure there is a more efficient way but that's the example from the help text.


    Simon Jones
    Thursday, August 18, 2011 11:05 AM
  • Hi,

    in the screendesigner thre's a property "Screenlayout" which has a property "Use write-protected controls" (toggle on/off).

    Does anybody knows if it's possible to use this property in code (make a controls changeable or not by button-click...)?

    Guido

    Thursday, August 18, 2011 11:45 AM
  • I think the official way is to use the IsReadOnly property of the control.
    Simon Jones
    Thursday, August 18, 2011 12:53 PM
  • If it is a gridview use this code

     

     

     For Each emp As EmployeeDetails In EmployeeDetailsSet

      FindControlInCollection("City", emp).IsVisible = false

     Next

     

     

    Saturday, August 20, 2011 10:49 AM