Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.5 Windows Forms
I had a user Control 'UC' which contains only one textbox. & Then using that UC in a windows Form for two times; i want to assign value of one textbox of UC1 to other textbox of UC2.how can we do this?
Thanks in advance.
Posted 25-Sep-12 2:30am
Edited 25-Sep-12 2:35am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Create a public property in the usercontrol - in the Getter, return the value of the TextBox.Text. In the setter, set the value. Then, in your parent form, you just copy from one property to the other.
 
public string Text
   {
   get { return myTextBox.Text; }
   set { myTextBox.Text = value; }
   }
myFirstUC.Text = mySecondUC.Text;
  Permalink  
Comments
Kapil Manspure at 25-Sep-12 8:29am
   
Thanks friend....but I have to use text change event of user control in that derived form.is it possible to do it? if yes then how? any solution will be appreciate.
Thanks in advance..
OriginalGriff at 25-Sep-12 8:42am
   
Yes - create your own UserControl TextChanged event - the Textbox one triggers that. It's easy to do: there is a tip here that provides the code and a simple way to add it as well if you want:
http://www.codeproject.com/Tips/400287/A-simple-code-snippet-to-add-an-event
(You only need the first two code blocks to add an event, the rest of the Tip is about making it quicker to do in Visual Studio, becasue I'm lazy!)
Kapil Manspure at 26-Sep-12 2:58am
   
Thanks OriginalGriff, but Sorry to asked this again I am a newbie in Windows forms & eventHandler, Delegates etc.. so please can you just elaborate some more to use the UC_Validated() event of derived form1 in TEXTCHANGE event of UserControl items? How to handle intercommunication of events?

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100