Collection Property

C

Chane

hi
Thanx to all, I'm created an usercontrol and writing my
own properties its working fine. But whether i grouped my
properties as unique it works but it won't assign values
to the control

Eg. MyUsercontrol having only one textBox. I'm writing
two properties like FirstName and LastName in separate
class. And in my main class i created object for that
class and write the group property. Like

public class Person
{
string FName;
string LName;
public string FirstName
{
get{return FName;}
set{FName=value;}
}
public string LastName
{
get{return LName;}
set{LName=value;}
}
}

Main Class:

public class MainCls
{
Person p = new Person();
[TypeConverter(typeof(ExpandableObjectConverter))]
public Person PersonColl
{
get{return p;}
set{p=value;textBox1.Text = p.FirstName + " " +
p.LastName;}
}

I don't know whether its correct or not. It displays the
properties in the property browser. I'm entered the value
but i won't assign to the textBox control. I wants to
assign that values. Thanx.
 
V

Vijaye Raji

Looks like you are entering the FName and LName values separately. From
your code, the textbox is not going to get your values this way - because
the variable "p" is being "modified" but not "set".

One way to get around the problem is to move the textbox text assigning code
to the class "Person" - but that breaks the OOP concept.

The other way is to throw in an event "NameChanged" on Person and look for
that event in the main class and update the textbox.

Hope this helps.

-vJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top