![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
|
HEre is a node class i just made:
public class ListNodeClass { private int ItemValue; private string ItemText; public ListNodeClass() { } public ListNodeClass(int Value, string Text) { ItemValue = Value; ItemText = Text; } public int Value { get { return ItemValue; } set { ItemValue = value; } } public string Text { get { return ItemText; } set { ItemText = value; } } } and here is how you can use it: System.Collections.ArrayList Nodes = new ArrayList(); for(int n=1;n<11;n++) { ListNodeClass NewNode = new ListNodeClass((n*10),"Item " + n.ToString()); Nodes.Add(NewNode); } lblItem->Text = ((ListNodeClass)Nodes[0]).Value.ToString(); txtItem->Text = ((ListNodeClass)Nodes[0]).Text; Hope this helps, Chi |
|
|
|
|
|
#12 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
You forgot the code tags, buddy!
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#13 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Purdy, ain' it?
![]()
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#14 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
![]()
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#15 |
|
Programming Guru
![]() ![]() ![]() |
Southerner's way of saying pretty.
![]()
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#16 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
Either that, or purdy was what Tweety called Sylvester.
|
|
|
|
|
|
#17 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
ChiHappens, that's C#, not C++ .NET. There's a difference, I'm afraid.
|
|
|
|
|
|
#18 |
|
Programmer
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3
![]() |
Ok, well, I still don't have an answer to my rather simple problem. I had VC++ make me a form object, with the corresponding Form1.h file.
I then went into the main .cpp file, and tried trying to access an object on the form, namely lblTotal, a label object. I reached the current mess I have now by randomly changing things: int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
(Form1::lblTotal)::Label::Text::set("some text");
// Form1::lblTotal->Text = and such also won't work.
return 0;
}And then I get the following errors: .\Till Program.cpp(19) : error C2143: syntax error : missing ';' before 'System::Windows::Forms::Label::Text::set' .\Till Program.cpp(19) : error C2597: illegal reference to non-static member 'TillProgram::Form1::lblTotal' .\Till Program.cpp(19) : error C2352: 'System::Windows::Forms::Label::Text::set' : illegal call of non-static member function Somebody mind telling me just how I get at form objects? |
|
|
|
|
|
#19 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
The Run method of application doesn't return until the application has finished anyway, so you can't execute code after the Run method and expect that the form is still around.
If you wanted to access the form fields from somewhere else (e.g. another form), then you could pass the form value to that other form. Something like: // Create the main window and run it
Form1 ^newForm1 = gcnew Form1();
newForm1->lblTotal->Text = "hello";
Application::Run(newForm1);Note that you would have to change the lblTotal field to "public" in Form1 |
|
|
|
|
|
#20 |
|
Programmer
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3
![]() |
Ah, so ok, so I just have to do all that stuff from within Form1.h. Which leads me to my next question:
Now from within Form1.h, on a certain button click, I want to read the text inside of txtItem, a standard textbox. I tried this: txtItem->Text = "0"; string current; current = txtItem->Text; but got these rather long errors: c:\documents and settings\sam\my documents\visual studio 2005\projects\till program\till program\Form1.h(469) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(875): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(880): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(885): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
while trying to match the argument list '(std::string, System::String ^)'Care to tell me how I should be doing it? Last edited by Twilight; Apr 21st, 2006 at 1:45 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|