Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to assign values to controls in UserControl 1

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
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
Get
Return txtTaxID.Text
End Get
Set(ByVal value As String)
txtTaxID.Text = value
End Set
End Property


Public Property CorpName() As String
Get
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.TabPages.Add(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.
 
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.
 
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:
Code:
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:

Code:
Dim ucCorpControl As CorpClass = New CorpClass
tc1.Controls.Add(ucCorpControl)

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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top