Click here to Skip to main content
15,892,746 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to check typ in string Pin
PIEBALDconsult2-May-08 8:26
mvePIEBALDconsult2-May-08 8:26 
QuestionC# Code Standards Pin
KBM731-May-08 21:10
KBM731-May-08 21:10 
AnswerRe: C# Code Standards Pin
Christian Graus1-May-08 21:18
protectorChristian Graus1-May-08 21:18 
AnswerRe: C# Code Standards Pin
Colin Angus Mackay1-May-08 22:18
Colin Angus Mackay1-May-08 22:18 
GeneralRe: C# Code Standards Pin
Vasudevan Deepak Kumar2-May-08 1:46
Vasudevan Deepak Kumar2-May-08 1:46 
AnswerRe: C# Code Standards Pin
Vasudevan Deepak Kumar2-May-08 1:44
Vasudevan Deepak Kumar2-May-08 1:44 
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 
Hello all. I need some assistance. If I have a form that has buttons (or any Control(s)) on it, and I want to be able to populate a datagridview at runtime by selecting the control name from a combobox, how do you call the GetValue(object, object[] index) method on it to get the value of the property. I have no problem getting the list of property names, but I cannot get the values!Mad | :mad:

This code works. All but the GetValue method. I keep getting a 'TargetException: Object does not match target type' error.
Please give me a code example of how to properly call this GetValue(object, object[] index) method.

Once again,

The method that updates the gridview(right now it is a textbox in this code; I will change it later) and the class that handles the properties:

private void myCboBox_SelectedIndexChanged(object sender, EventArgs e)
{
MyProperty Myproperty = new MyProperty(null, null);

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

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

PropertyInfo[] myProps = t.GetProperties();

foreach (PropertyInfo p in myProps)
{
richTextBox1.Text += "\n" +

//This GetValue(object, object[] index)
//is what I need to know how to do:
p.Name + "\t\t\t\t" + p.GetValue(Myproperty, null);
}
}
}

public class MyProperty
{
public MyProperty(string aName, object aValue)
{
theName = aName;
theValue = aValue;
}
private string theName;

public string theNameProp
{
get { return theName; }
set { theName = value; }
}

private object theValue;

public object intTest2
{
get { return theValue; }
set { theValue = value; }
}
}

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

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 

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.