Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,

i have a window based vb.net application with 2 forms and 1 usercontrol.

In Form 1:
1 listbox and 1 button.

In Form 2: [main form / start-up form]
1 tabcontrol [named tabs]

In Usercontrol [named createcontrol]:
1 Textarea

On form2 load event:

Dim NewTab As New TabPage
  With NewTab
  Name = "some name"
  .Text = "some text"
End With

Dim myChat As New createcontrol()
NewTab.Controls.Add(myChat)
tabs.TabPages.Add(NewTab)


i can have multiple tabpages with usercontrol

Now what i want When some one click on form1,
-> select one list items from listboox
-> press button
-> selected item is set in textbox control of a usercontrol

like textbox.text = selected [text from list box]


thanks in advance
Posted
Updated 21-Apr-11 2:41am
v2

That is a very bad idea.

It ties the design of the top items together: you can't change the UserControl without it affecting the users of the control, and them being forced to make changes to working code.

Instead, set up a public property in the the control which you can set and get the value of, which puts the string to the appropriate TextBox. That way, you could later replace the TextBox with (say) a ComboBox without affecting the outside world.
 
Share this answer
 
Hi,

There are two methods by which you can achieve this

1. Make your textbox Object public and use it directly(Not Recomended for the point of View of OOPS).

2. Create a public function\Property in your user control and use it to assign values.

regards
Ankit
 
Share this answer
 
v2
Comments
kals84 21-Apr-11 8:35am    
Suppose i have 3 tabs in tab control. All tab pages have usercontrol. Than how do i access textbox for individual user control ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900