CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [RESOLVED] checkedlistbox remove

    Well, this code works, so this is primarily FYI, but it can be simplified considerably.

    The part marked in red in the following line has no effect and can be omitted as well:

    Code:
    	for(int x = 0; x < checkedListBox1->CheckedItems->Count; checkedListBox1->CheckedItems->Count)
    You certainly know that this code is meant to advance the loop variable (in this case x), and therefore x always remains 0 during the entire loop. (BTW, the equivalent in the for loop in post #1 actually did what it was supposed to do - and exactly that was what caused the problem.)

    As a consequence of this, your code is equivalent to this:

    Code:
    String ^ s;
    while (checkedListBox1->CheckedItems->Count > 0)
    {
    	s = String::Concat(s, checkedListBox1->CheckedItems[0],"\n");
    	checkedListBox1->Items->Remove(checkedListBox1->CheckedItems[0]);
    }
    MessageBox::Show(s, "Istrinti is pasirinkimo saraso");
    Well, strictly speaking it is not exactly equivalent. To make it that, you can wrap the whole thing in an uncontrolled {} to limit the lifetime of s.

    BTW, forums like this one are also a great English training.
    Last edited by Eri523; January 18th, 2011 at 08:12 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

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