Click here to Skip to main content
15,887,175 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Code Standards Pin
Kevin McFarlane2-May-08 4:05
Kevin McFarlane2-May-08 4:05 
QuestionSystem.Reflection GetValue method Pin
MrColeyted1-May-08 20:49
MrColeyted1-May-08 20:49 
AnswerRe: System.Reflection GetValue method Pin
Hesham Amin2-May-08 2:27
Hesham Amin2-May-08 2:27 
QuestionHow to read files that are locked exclusively by other applications? Pin
JohnsonDesouza1-May-08 20:17
JohnsonDesouza1-May-08 20:17 
AnswerRe: How to read files that are locked exclusively by other applications? Pin
N a v a n e e t h1-May-08 20:59
N a v a n e e t h1-May-08 20:59 
AnswerRe: How to read files that are locked exclusively by other applications? Pin
Christian Graus1-May-08 21:07
protectorChristian Graus1-May-08 21:07 
AnswerRe: How to read files that are locked exclusively by other applications? Pin
Luc Pattyn1-May-08 22:21
sitebuilderLuc Pattyn1-May-08 22:21 
Questionstatus strip - show some text Pin
lgatcodeproject1-May-08 20:17
lgatcodeproject1-May-08 20:17 
AnswerRe: status strip - show some text Pin
John Ad1-May-08 21:01
John Ad1-May-08 21:01 
QuestionRe: status strip - show some text Pin
lgatcodeproject1-May-08 21:32
lgatcodeproject1-May-08 21:32 
AnswerRe: status strip - show some text Pin
Thomas Stockwell2-May-08 10:39
professionalThomas Stockwell2-May-08 10:39 
QuestionDynamically add a property item to Property Grid Pin
Varad_Rajan1-May-08 20:02
Varad_Rajan1-May-08 20:02 
AnswerRe: Dynamically add a property item to Property Grid Pin
visualhint6-May-08 5:46
visualhint6-May-08 5:46 
QuestionNeed Help on Writing to New Line Pin
Thomas Toh1-May-08 17:59
Thomas Toh1-May-08 17:59 
AnswerRe: Need Help on Writing to New Line Pin
PIEBALDconsult1-May-08 19:05
mvePIEBALDconsult1-May-08 19:05 
AnswerRe: Need Help on Writing to New Line Pin
Christian Graus1-May-08 19:32
protectorChristian Graus1-May-08 19:32 
AnswerRe: Need Help on Writing to New Line Pin
Luc Pattyn1-May-08 22:26
sitebuilderLuc Pattyn1-May-08 22:26 
QuestionComboBox in Datagrid view Pin
cocoonwls1-May-08 17:18
cocoonwls1-May-08 17:18 
AnswerRe: ComboBox in Datagrid view Pin
Gopal.S1-May-08 21:12
Gopal.S1-May-08 21:12 
GeneralRe: ComboBox in Datagrid view Pin
cocoonwls1-May-08 22:45
cocoonwls1-May-08 22:45 
QuestionMember Function Pointers usage on class instances: Pin
Net Guy1-May-08 17:14
Net Guy1-May-08 17:14 
AnswerRe: Member Function Pointers usage on class instances: Pin
Christian Graus1-May-08 17:19
protectorChristian Graus1-May-08 17:19 
QuestionReflection Question Pin
MrColeyted1-May-08 16:49
MrColeyted1-May-08 16:49 
Hello all! I have a college project due tomorrow and I am in dire need of some assistance! The project requires that I create a plain windows form with six controls on it; I have chosen six buttons. Form2 will be the startup form, will have a combobox and a DataGridView (I am using a richTextBox right now, but will change that once the rest works). The names of the controls from Form1 populate the combobox in Form2. By selecting one of the controls from the combobox, all of that controls' properties are then listed in the DataGridView.
I have most of it working, but I cannot get the value for each property using the GetValue(object, object[] index) method. I have tried all that I can think of, but cannot get it to work. Mad | :mad: Confused | :confused: The code that I have for Form2 is as follows:

Here, the main problem is on the bottom line of code. I have commented there.

public partial class Form2 : Form
{

//Declares an Array of type Controls:
Control[] controls;

public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
//Creates an instance of Form1:
Form1 myForm = new Form1();

//Initializes the Control[] by calling the getControls() method on Form1:
controls = myForm.getControls();

//Adds the Control names to the ComboBox:
foreach (Control c in controls)
{
myCboBox.Items.Add(c.Name);
}
}

private void myCboBox_SelectedIndexChanged(object sender, EventArgs e)
{

//creates an int to hold the selected index:
int index = myCboBox.SelectedIndex;

//creates a type variable:
Type t = controls[index].GetType();

//clears any previous entries:
richTextBox1.Clear();

foreach (PropertyInfo prop in t.GetProperties())
{
//Here, the GetValue method will not work! I have tried passing everything that I can think of to it
//and still it will not work. It keeps telling me that target object does not match.
//Please help.
richTextBox1.Text += "\n" +
prop.Name + "\t\t:" + prop.GetValue(t, null);
}
}
}

"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra

AnswerRe: Reflection Question Pin
PIEBALDconsult1-May-08 19:07
mvePIEBALDconsult1-May-08 19:07 
GeneralRe: Reflection Question Pin
MrColeyted1-May-08 19:22
MrColeyted1-May-08 19:22 

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.