CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Question 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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: how summing the numbers in the listbox

    This Forum is for native VC++, not for Managed C++/CLI code
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: how summing the numbers in the listbox

    [ redirected ]

    Do you want to say listBox2->Items[i] instead of listBox2->Items->Item[i]?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    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
  •  





Click Here to Expand Forum to Full Width

Featured