Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

Deleting checked items in CheckedListBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robke - 26 Oct 2004 13:54 GMT
Hi,

I've had problems deleting checked items from CheckedListBox. Tried searching
the web for solution and then a nice idea came into my mind. Recursion!

So I wrote a simple function:

private void deleteItems(int index)
{
   if (checkedListBox1.Items.Count <= index)
       return;
   else
   {
       if (checkedListBox1.GetItemCheckState(index) == CheckState.Checked)
       {
           checkedListBox1.Items.RemoveAt(index);
           deleteItems(index);
       }
       else deleteItems(index+1);
   }
   return;
}

private void button1_Click(object sender, System.EventArgs e)
{
   deleteItems(0);
}

Regards,
Robke
Stoitcho Goutsev \(100\) [C# MVP] - 26 Oct 2004 14:56 GMT
Hi Robke,

Isn't it easier if you do something like the following

while(this.checkedListBox1.CheckedIndices.Count > 0)
  {
   this.checkedListBox1.Items.RemoveAt(checkedListBox1.CheckedIndices[0]);
  }

Signature

HTH
Stoitcho Goutsev (100) [C# MVP]

> Hi,
>
[quoted text clipped - 27 lines]
> Regards,
> Robke

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.