|
-
October 7th, 2010, 05:35 AM
#1
how summing the numbers in the listbox
the numbers in the listbox were added from the textbox.
after the numbers added, I want to summing the numbers in the listbox.
I've made this code but It didn't work:
Code:
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
{
int i,jum, x, y;
{
listBox2->Items->Add(txt_add->Text);
}
x=listBox2->Items->Count;
for(i=0; i<=x; i++)
{
y = Convert::ToInt32(listBox2->Items->Item[i]); //ERROR LINE
jum += y;
}
txt_total2->Text=jum.ToString();
}
I got this error:
Code:
error C3293: 'Item': use 'default' to access the default property (indexer) for class 'System::Windows::Forms::ListBox::ObjectCollection'
can you tell me what's wrong with that code, and what is the right code to solve my case?
-
October 7th, 2010, 05:49 AM
#2
Re: how summing the numbers in the listbox
This Forum is for native VC++, not for Managed C++/CLI code
Victor Nijegorodov
-
October 7th, 2010, 07:29 AM
#3
Re: how summing the numbers in the listbox
[ redirected ]
Do you want to say listBox2->Items[i] instead of listBox2->Items->Item[i]?
-
October 7th, 2010, 07:41 AM
#4
Re: how summing the numbers in the listbox
Also,
for(i=0; i<=x; i++)
should be
for(i=0; i<x; i++)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|