Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

My goal is to create an application that determines which check boxes ARE NOT checked in a checkedlistbox and run a command based off of those unchecked check boxes.

 

I have only been able to find the opposite - running a command based off of checked check boxes. Here is my code right now:

 

Imports Microsoft.Win32
Imports System.IO

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
       For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
           Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
               Dim _Users, _Username As String
               _Users = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
               _Username = System.IO.Path.GetFileNameWithoutExtension(_Users)
               CheckedListBox1.Items.Add(_Username)
               CheckedListBox1.Items.Remove("systemprofile")
               CheckedListBox1.Items.Remove("LocalService")
               CheckedListBox1.Items.Remove("NetworkService")
               CheckedListBox1.Items.Remove("Administrator")
               CheckedListBox1.Items.Remove("administrator")
           End Using
       Next

   End Sub

   Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
       System.Diagnostics.Process.GetCurrentProcess.CloseMainWindow()
       System.Diagnostics.Process.GetCurrentProcess.Close()
       System.Diagnostics.Process.GetCurrentProcess.Kill()
   End Sub

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       ' Display in a message box all the items that are checked.
       Dim itemChecked As Object
       Const quote As String = """"


       For Each itemChecked In CheckedListBox1.CheckedItems
           ' Use the IndexOf method to get the index of an item.
           MessageBox.Show("User account:" + quote + itemChecked.ToString + quote + _
                           " will be added to the User State Migration.")

       My.Computer.FileSystem.DeleteDirectory("C:\Users\" & itemChecked.ToString(), FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)

       Next
       Me.Close()
   End Sub
End Class

 

As you can see it only deletes the directory based off of the checked check boxes. Anyone have any idea on how to do the opposite? I have tried multiple False combinations. I am using Visual Studio 2010. Thanks. :D

Edited by snarfblam
  • Leaders
Posted

Well, instead of only looping over the checked items, why not loop all items and use an "if" statement to test each item and see whether it's checked. Assuming you have no duplicates in your list, you can use this little bit of code to test whether an item is checked.

 

Dim ItemIsChecked As Boolean = CheckedListBox1.CheckedItems.Contains([color="Blue"][i]item[/i][/color])

[sIGPIC]e[/sIGPIC]
Posted
Ok thanks, I'll try it out. What would I put in the contains field (item)? The check boxes are generated based off of the users on the computer so every computer that uses this application will have different check box options. Can you give me an example of this and an IF statement to check for unchecked check boxes? Thanks.
  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...