Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


How to assign values to controls in UserControl

How to assign values to controls in UserControl

How to assign values to controls in UserControl

I created a user control (CorpControl) with a handful of controls as text boxes (txtTaxID) , combo boxes (cboHQ), button and datetimepickers.

Public Class CorpControl

Private Sub CorpControlControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Public Property TaxID() As String
Return txtTaxID.Text
End Get
Set(ByVal value As String)
txtTaxID.Text = value
End Set
End Property

Public Property CorpName() As String
Return txtCorpName.Text
End Get
Set(ByVal value As String)
txtCorpName.Text = value
End Set
End Property

End Class

I added a class to my project CorpClass

Public Class CorpClass
Inherits TabPage

Public Sub New()

Me.Controls.Add(New CorpControl)

End Sub

End Class

I added this tab page to a tab control in my form:

Dim tpCorp As New CorpClass
tpCorp.Text = "Corporate Information"
tpCorp.name = "tpCorp"
TabControl1.SelectedTab = tpCorp

Tried setting values to the controls but getting errors

tpCorp.TaxID = "123"

Can anybody show me how to assign values to the textboxes (for now) in this new tab?

Any help will be greatlyu appreciated.

RE: How to assign values to controls in UserControl

I was able to add a usercontrol (ucMaint) form to parent form (frm1) as a tab page (tpMaint) in
a Tab Control (tc1)
In the user control, I have a button (btn1).
How and where do I create an onclick event handler for this button.
When this button is clicked, I need to add copy of the tab page in the same tab control.

RE: How to assign values to controls in UserControl

There are a couple of different ways you can handle this.

One, you can just add the button's handler to the user control's code, just like on a normal Windows form.

Two, you can add an event to the user control, then have the button click raise that event, and handle the event on the parent form. In the user control, put this:


Public Event ButtonClick()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    RaiseEvent ButtonClick()
End Sub 

This will send the button click event to the parent form, where you can handle it like this:


Dim ucCorpControl As CorpClass = New CorpClass

AddHandler ucCorpControl.ButtonClick, AddressOf UCButton_Click

Private Sub UCButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    'do your stuff here
End Sub 

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close