Click here to Skip to main content
15,905,504 members
Home / Discussions / C#
   

C#

 
GeneralRe: need help, treeView and active directory Pin
vcorn14-Jun-04 8:27
vcorn14-Jun-04 8:27 
GeneralRe: need help, treeView and active directory Pin
Dave Kreskowiak14-Jun-04 8:34
mveDave Kreskowiak14-Jun-04 8:34 
GeneralUnloading AppDomain Pin
Ami Bar14-Jun-04 5:50
Ami Bar14-Jun-04 5:50 
GeneralRe: Unloading AppDomain Pin
Heath Stewart14-Jun-04 6:43
protectorHeath Stewart14-Jun-04 6:43 
GeneralRe: Unloading AppDomain Pin
Ami Bar14-Jun-04 10:35
Ami Bar14-Jun-04 10:35 
GeneralRe: Unloading AppDomain Pin
Heath Stewart14-Jun-04 11:01
protectorHeath Stewart14-Jun-04 11:01 
GeneralReflection Assistance please! Pin
Kasdoffe14-Jun-04 5:23
Kasdoffe14-Jun-04 5:23 
GeneralRe: Reflection Assistance please! Pin
Heath Stewart14-Jun-04 6:38
protectorHeath Stewart14-Jun-04 6:38 
It depends - is the TextBox a field or property declared in your container (i.e., Form, UserControl, etc.) or is it simply a variable? Reflection only works on type metadata, so if it's a variable it won't work.

If it is a field, then you could do something like this:
public void SetText(string name, string text)
{
  FieldInfo field = this.GetType().GetField(name);
  if (field != null)
  {
    PropertyInfo prop = field.FieldType.GetProperty("Text");
    if (prop != null && prop.CanWrite)
    {
      object obj = field.GetValue(this);
      prop.SetValue(obj, text, null);
    }
  }
}
This also works best when you don't specify the Name properties of controls, which isn't required (the designer does, though).

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Reflection Assistance please! Pin
Anonymous14-Jun-04 7:02
Anonymous14-Jun-04 7:02 
GeneralRe: Reflection Assistance please! Pin
Heath Stewart14-Jun-04 8:46
protectorHeath Stewart14-Jun-04 8:46 
GeneralRe: Reflection Assistance please! Pin
Kasdoffe14-Jun-04 7:37
Kasdoffe14-Jun-04 7:37 
GeneralRe: Reflection Assistance please! Pin
Kasdoffe14-Jun-04 8:32
Kasdoffe14-Jun-04 8:32 
Generallooking for a tool or utility Pin
Anonymous14-Jun-04 4:54
Anonymous14-Jun-04 4:54 
GeneralRe: looking for a tool or utility Pin
Dave Kreskowiak14-Jun-04 5:07
mveDave Kreskowiak14-Jun-04 5:07 
GeneralRichTextBox selection color Pin
Judah Gabriel Himango14-Jun-04 4:31
sponsorJudah Gabriel Himango14-Jun-04 4:31 
GeneralRe: RichTextBox selection color Pin
Heath Stewart14-Jun-04 4:49
protectorHeath Stewart14-Jun-04 4:49 
GeneralRe: RichTextBox selection color Pin
Judah Gabriel Himango14-Jun-04 5:02
sponsorJudah Gabriel Himango14-Jun-04 5:02 
GeneralUpload files using SPS 2003 Pin
Member 67053114-Jun-04 4:16
Member 67053114-Jun-04 4:16 
GeneralUsing System.Data Pin
Simon Wren14-Jun-04 4:08
professionalSimon Wren14-Jun-04 4:08 
GeneralRe: Using System.Data Pin
Heath Stewart14-Jun-04 4:30
protectorHeath Stewart14-Jun-04 4:30 
GeneralEmbedded User Control in IE Problem Pin
Yolan14-Jun-04 3:45
Yolan14-Jun-04 3:45 
GeneralRe: Embedded User Control in IE Problem Pin
Heath Stewart14-Jun-04 3:56
protectorHeath Stewart14-Jun-04 3:56 
GeneralRe: Embedded User Control in IE Problem Pin
Yolan14-Jun-04 4:09
Yolan14-Jun-04 4:09 
GeneralRe: Embedded User Control in IE Problem Pin
Heath Stewart14-Jun-04 4:24
protectorHeath Stewart14-Jun-04 4:24 
GeneralRe: Embedded User Control in IE Problem Pin
Yolan14-Jun-04 4:34
Yolan14-Jun-04 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.