|
-
Oct 25th, 2008, 06:11 AM
#1
Thread Starter
Addicted Member
Last edited by ishrar; Nov 5th, 2008 at 06:16 AM.
-
Oct 25th, 2008, 06:53 AM
#2
Re: Control property dymicaly assignment
Im not at a computer with .NET right now, but that can easily be done with the use of reflection. However why not just give the user access to the control reference so he can access the properties direclty, the "proper" way? That would be alot more efficient and a better design.
However if you still wish to do this, you'd need to do something like this:
(this might or might not be 100% correct, as it is off the top of my head)
CSharp Code:
private void SetProperty(Control ctrl, string propName, object propValue){ System.Reflection.PropertyInfo propInfo = ctrl.GetType().GetProperty(propName); if(propInfo != null){ propInfo.SetValue(ctrl, propValue, null); } }
-
Oct 25th, 2008, 07:43 AM
#3
Thread Starter
Addicted Member
Re: Control property dymicaly assignment
Hmmm nice.....
I was not aware of it...
You have given me an exact function which I desired....
Thanks Man..
Thanks A lot.
-
Nov 5th, 2008, 06:02 AM
#4
Thread Starter
Addicted Member
Re: [RESOLVED] Control property dymicaly assignment
@Atheist Thank you man. Again I have problem with this thing. I can assign all properties of control.But I don't know how I can assign subproperty using this method
i.e.
If I want Column.Count of DataGridView then what should I do?
Code:
System.Reflection.PropertyInfo propInfo = Button1.GetType().GetProperty("Fonts.Bold");
propInfo.GetValue(Button1,null);
Please suggest me some way.
Thank you.
Last edited by ishrar; Nov 5th, 2008 at 06:12 AM.
-
Nov 5th, 2008, 08:33 AM
#5
Not NoteMe
Re: Control property dymicaly assignment
You'd have to alter your function so that Ctrl was an object, then you'd call it something like this.
Code:
SetProperty(MyGridView.Columns, "Count", 5
I think that should do the trick.
P.S. You didn't need to duplicate question as a new thread. Lots of people check these forums and as long as the thread isn't marked as resolved they'll assume you need more help that has been given so far.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Nov 5th, 2008, 06:06 PM
#6
PowerPoster
Re: Control property dymicaly assignment
you do realise that Reflection is expensive? you can pretty much probably achieve the same thing by having a propertygrid control... and let the user change properties via that based on what properties you want to expose on the control selected....
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
|