How do I change a control's content through the Controls collection?
-
Here are two different code approaches I have used, but neither works.
int i = thisForm.GetChildIndex(textBox);
thisForm.Controls[index].Text = "Something";
thisForm.Controls[index].Invalidate();and
Control controlTest = thisForm.textBox;
controlTest.Text = "Something";
controlTest.Invalidate();The reason I'm trying to do this is that I would like to be able to "map" controls to fields in a database (I'd like to do it myself rather than do data-binding), so I need a way to be able to create a list (or other collection) of controls and the data field to put in that control. It is rather like UpdateData in VC++. But I can't seem to update the screen with code like what I've shown above. How do I go about this? I hope the question makes sense because I'm sure one of you guys knows how to do it if I can just figure the right way to ask the question. Thanks.
-
Here are two different code approaches I have used, but neither works.
int i = thisForm.GetChildIndex(textBox);
thisForm.Controls[index].Text = "Something";
thisForm.Controls[index].Invalidate();and
Control controlTest = thisForm.textBox;
controlTest.Text = "Something";
controlTest.Invalidate();The reason I'm trying to do this is that I would like to be able to "map" controls to fields in a database (I'd like to do it myself rather than do data-binding), so I need a way to be able to create a list (or other collection) of controls and the data field to put in that control. It is rather like UpdateData in VC++. But I can't seem to update the screen with code like what I've shown above. How do I go about this? I hope the question makes sense because I'm sure one of you guys knows how to do it if I can just figure the right way to ask the question. Thanks.
I wonder if you need to cast it to be a textbox first ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
I wonder if you need to cast it to be a textbox first ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Thanks for the suggestion, but it turns out the problem was something totally different. The textbox in question is part of a CustomControl, and when I declared the public Attribute for Text I accidentally used the "new" keyword instead of "override". So, when I set .Text for the control, it was not actually setting the .Text for the TextBox part of the CustomControl like it was supposed to. Turns out the code snippet I put in my original message DOES work just fine. Thanks anyway for the response.