blankon
October 7th, 2010, 05:35 AM
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:
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:
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?
after the numbers added, I want to summing the numbers in the listbox.
I've made this code but It didn't work:
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:
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?