-
September 5th, 2006, 01:08 AM
#1
Separating Control Properties for multiple User Controls
I have written a User Control which has a button and a text box on it. The textbox is updated by using
UserControlTxtBox.Text= someValue;
This works fine if there is one User Control on a form.
If I have 2 or more, the first User Control works ok initially, but once I start to access the Text property of the TextBox on the second control, both Text properties on both controls get updated with the same information from then on. It seems to be updating the User Controls' textBox rather than the base control individually.
Any idea on how I can fix this?
Regards
alias47
-
September 5th, 2006, 02:05 AM
#2
Re: Separating Control Properties for multiple User Controls
It is hard to tell with only this information. Can you post the code for the Control implementation? Can you post the code for the Control declarations on the form?
-
September 5th, 2006, 02:31 AM
#3
Re: Separating Control Properties for multiple User Controls
In the UserControl:
Code:
this.txtCell = new System.Windows.Forms.TextBox();
this.btnCell = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtCell
//
this.txtCell.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtCell.Location = new System.Drawing.Point(0, 3);
this.txtCell.Multiline = true;
this.txtCell.Name = "txtCell";
this.txtCell.Size = new System.Drawing.Size(143, 21);
this.txtCell.TabIndex = 0;
this.txtCell.Click += new System.EventHandler(this.txtCell_Click);
Code that sets the Text property:
Code:
txtCell.Text="Text";
In the Form:
Code:
// Cell1
//
this.Cell1.AllowDrop = true;
this.Cell1.Location = new System.Drawing.Point(125, 90);
this.Cell1.Name = "Cell1";
this.Cell1.Size = new System.Drawing.Size(141, 20);
this.Cell1.TabIndex = 8;
//
// Cell2
//
this.Cell2.AllowDrop = true;
this.Cell2.Location = new System.Drawing.Point(125, 50);
this.Cell2.Name = "Cell2";
this.Cell2.Size = new System.Drawing.Size(141, 20);
this.Cell2.TabIndex = 7;
-
September 5th, 2006, 02:35 AM
#4
Re: Separating Control Properties for multiple User Controls
To bewa:
I am attempting to set the Text Property from within the UserControl. The user needs to add my UserControl to their form and should not need to write any code to get it to work correctly.
Regards
-
September 5th, 2006, 02:51 AM
#5
Re: Separating Control Properties for multiple User Controls
Bewa's code shows the principles.
From your code I have seen nothing wrong so far.
If I understand everything correctly, you do not update the textbox via code from the form.
Are the text boxes data bound?
I think we still need more code, where are the textboxes updated via code?
Probably you can figure it out by yourself by placing breakpoints in each place where the text box is updated, look how you got there.
-
September 5th, 2006, 02:51 AM
#6
Re: Separating Control Properties for multiple User Controls
So basicly, you want the *same* type of usercontrol to behave *differently* without changing any of it's properties? That is, by all means, absurd if you ask me.
I probably just don't get waht you are trying to do.
-
September 5th, 2006, 02:54 AM
#7
Re: Separating Control Properties for multiple User Controls
Thanks for your help so far...
What I thought was possible:
A user clicks the text box in one of the User Controls. Some stuff happens. Result is returned to that TextBox.
A user clicks the text box in another User Control. Some stuff happens. Result is returned to that TextBox.
Regards
alias47
-
September 5th, 2006, 02:07 AM
#8
Re: Separating Control Properties for multiple User Controls
The way I do this, in the usercontrol I add a property:
Code:
public string SetText
{
set
{//Textbox1 is the textbox in your usercontrol
this.textBox1.Text = value;
}
get
{
return this.textBox1.Text;
}
}
Then in your form:
usercontrol1.SetText= "Que pasa?" ;
usercontrol2.SetText= "SomeOtherText";
Greetzzzz...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|