Solved

VB Clearing Controls

Posted on 2014-10-07
2
144 Views
Last Modified: 2014-10-07
Hi
I create Controls in a Tabpage called extraTabPage

dim txt as new system.windows.forms.TextBox
dim pkr as new system.windows.forms.DateTimePicker
dim btn as new system.windows.forms.Button

extratabpage.Control.Add(txt)
extratabpage.Control.Add(pkr)

I add about 3 or 4 of each setting height and position as I go

Then create a button

extratabpage.Control.Add(btn)
btn.text = "Clear Entries"
add Handler btn.click, address of ClearEntries

End sub

Private Sub ClearEntries(ByVal eventsender As System.Object, ByVal eventargs As System.EventArgs)
            Dim ctrl As Control
            For Each ctrl In mExtraTabPage.Controls
                If (ctrl.GetType() IsNot CType(ctrl, Button)) Then
                    If (ctrl.GetType() Is CType(ctrl, TextBox)) Then
                        Dim txt As TextBox = CType(ctrl, TextBox)
                        txt.Text = ""
                    End If
                    If (ctrl.GetType() Is CType(ctrl, DateTimePicker)) Then
                        Dim Cal As DateTimePicker = CType(ctrl, DateTimePicker)
                        Cal.Format = DateTimePickerFormat.Custom
                        Cal.CustomFormat = " "
                    End If
                End If
            Next
        End Sub

when the clearentries is called I get an error

Unable to cast object of type system.windows.forms.button to type system.windows.forms.TextBox

Thanks
0
Comment
Question by:Kevinfeening
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 500 total points
ID: 40367376
>If (ctrl.GetType() IsNot CType(ctrl, Button)) Then

In the past I would use TypeOf like this:
If Not TypeOf(ctrl) Is Button Then

Not sure if this still works...
0
 

Author Closing Comment

by:Kevinfeening
ID: 40367428
worked
had to use in body of code as well as
if typeof(ctrl) is textbox then to clear the text box
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question