Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB
How to pass values from a form to user control Smile | :)
Posted 10-Dec-09 20:43pm
Edited 10-Dec-09 20:44pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Define public properties for the user control. Then the form can pass values by setting these properties.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Create a property inside your user control, and assign this value from the parent form.
for example
inside the control
public string MyProprty {get;set;}
 
inside the parent 
myControl.MyProperty = "string Value";
  Permalink  
Comments
Member 9950702 at 16-May-14 3:43am
   
i did this to show if it is working,
UserControl1 usr = new UserControl1();
usr.MyProprty = "Boom";
MessageBox.Show(usr.MyProprty + "");
yea it's working.
but if i add a messagebox inside my usercontrol .
like this.
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(MyProprty+"");
}
popping up an empty box -_- idk what to do.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Where do I put myControl.MyProperty = "string Value"; ? What "parent" are you refering to?
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 202
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 15 Feb 2011
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