Reputation: 429
HI all,
Please help me with this:
I have a form which contains my custom control.
In the custom control, I have 2 collections referencing to the same DataSource to get data.
My current CodeDOM serializer working like this:
control1.Values.DataSource = new objA();
control1.CategoryNames.DataSource = new objA();
As you can see, the objA was instantiated 2 time.
How to solve this?
I guess I can declare a variable that hold reference to the objA, then assign that variable to 2 collections:
ObjA var = new objA();
control1.Values.DataSource = var;
control1.CategoryNames.DataSource = var;
But I cannnot ensure the "var" is an unique name. How can I get it automatically assigned exactly the name Form gave to my control (control1, control2 and so on)?
Thank you.
Upvotes: 0
Views: 443
Reputation: 8073
As an alternative, you could name the variable as a guid. It's not guaranteed to be unique, but it's very likely that it will be (especially if none of the other variables in your class are named as guids).
You'll need to do some filtering on it to make it a valid variable name, such as making sure it starts with a letter, and removing the dashes.
string variableName = "A" + Guid.NewGuid().ToString().Replace("-","");
Upvotes: 1