Results 1 to 6 of 6

Thread: Programatically reset Formview values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Location
    Newark-on-trent, Nottingham
    Posts
    243

    Programatically reset Formview values

    Does anyone know how to programically clear the data from a form view using vb.net. I have so far come up with the following:

    Code:
                    Dim x
                    For x = 0 To Me.Controls.Count - 1
    
                        'if it is a text box then clear it 
                        If TypeOf FormView7.Controls.Item(x) Is TextBox Then
                            Dim text As TextBox = FormView7.Controls.Item(x)
                            text.Text = ""
                        End If
    
                    Next
    But i get the error "Specified argument was out of the range of valid values.
    Parameter name: index"

  2. #2
    New Member
    Join Date
    Dec 2008
    Posts
    14

    Re: Programatically reset Formview values

    try

    Code:
    If TypeOf FormView7.Controls.Item(x) Is TextBox Then
    
    dim mm as textbox = directcast (formview7.control.item(x), textbox)
    mm.text = ""
    
                        End If

    this should help !!!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Location
    Newark-on-trent, Nottingham
    Posts
    243

    Re: Programatically reset Formview values

    Same error but specifically pointing to "If TypeOf FormView7.Controls.Item(x) Is TextBox Then"

  4. #4
    New Member
    Join Date
    Dec 2008
    Posts
    14

    Re: Programatically reset Formview values

    try this

    Code:
       Dim ctrl As Control
    
            For Each ctrl In formview7.Controls
    
                If TypeOf ctrl Is textbox Then
                    Dim txt1 As textbox
                    txt1 = DirectCast(ctrl, textbox)
                  
                    txt1.text = ""
    
                End If

  5. #5
    New Member
    Join Date
    Dec 2008
    Posts
    14

    Re: Programatically reset Formview values

    just use the above routine i sent....

    remove ur for loop... and use this one instead

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Location
    Newark-on-trent, Nottingham
    Posts
    243

    Re: Programatically reset Formview values

    Still not working, i would rather hoping there would be a formview7.reset or something similar heres the code i have at present with thanks to your asssistance:

    Code:
                    Dim ctrl As Control
    
                    For Each ctrl In FormView7.Controls
    
                        If TypeOf ctrl Is TextBox Then
                            Dim txt1 As TextBox
                            txt1 = DirectCast(ctrl, TextBox)
                            txt1.Text = ""
                        End If
    
                    Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width