Luc Thank you for a prompt and elegant solution to my problem. Regards Martyn
Dowse
Posts
-
Realtime update of Label -
Realtime update of LabelHi all I am trying to display the value of a variable in a label. Easy enough I hear you say, but the variable can be changed by many different methods and functions, (some in dll's,) none of which trigger any specific event that I would normally use to update the label. I need the label to show the current value of the variable in 'real time.'
public class MyClass
{
public DateTime datStart;
public DateTime datNext; <======== This is the one I'm trying to show
public int intParam1;
public int intParam2;
//Extra fields removed for clarity
}And then in my form code:
MyClass _myVar = new MyClass();
I have a label called lblInformation that I would like to always show the value of _myVar.datNext.ToString() I've spent many hours trying to find a solution so any help will be very much appreciated. Thank you
-
Enumerate Custom ClassLuc, I managed to re-work your example to give me just what I was after. Thanks for putting me on the right track:
private void ShowData()
{
Type type = typeof(MyClass);
FieldInfo[] fi = type.GetFields();foreach (FieldInfo info in fi) { Debug.WriteLine(info.Name + " = " + info.GetValue(varMyClass)); } }
varMyClass is a variable of type MyClass. Thanks to all who helped.
modified on Thursday, July 2, 2009 1:41 PM
-
Enumerate Custom ClassThomas I will read up on reflection. It seems to be what I was after. Thank you.
-
Enumerate Custom ClassThank to all that responded to my post. Luc, I think I can re-work your example to give me what I was after. Thank you.
-
Enumerate Custom ClassThomas Thank you for taking the time to reply to my post. I am trying to implement foreach(object o in MyClass) for reporting and (possibly) serialization.
-
Enumerate Custom ClassHi all Have started writing a Class to help me with a problem in my current project and I would like to be able enumerate the variables in the Class by using a 'foreach(object o in MyClass)' in my main program. I was getting a 'MyClass does not contain a public definition for GetEnumerator' but have worked out why and I am at the point where I could really do with some help with the GetEnumerator function.
public class MyClass : IEnumerable
{
public System.DateTime datStart; //Schedule start date
public System.DateTime datEnd; //Date of final occurrence (#1/1/1900# if N/A)
public int intParam1; //Various Uses
public int intParam2; //Various Uses
//Other fields remove for clarity//Constructor public MyClass() { //Set defaults for new MyClass() datStart = new DateTime(1900, 1, 1); datEnd = datStart; intParam1 = -1; intParam2 = -1; } IEnumerator IEnumerable.GetEnumerator() { //What goes here? return null; //Only added this line to stop compiler error }
}
I know there are many, (many, many,) references to this on the web but I haven't been able to re-work any of them to solve my specific problem. Any help would be MUCH appreciated. Thank you.