Synapse Posted August 17, 2004 Share Posted August 17, 2004 I have a list box on my form that when Command Button 1 is clicked it gets all the Services.Private Sub Command1_Click() Dim Service As Variant For Each Service In GetObject("winmgmts:").ExecQuery("select * from Win32_Service") List1.AddItem Service.DisplayName Next Command1.Enabled = FalseEnd SubThat gets all the Services and displays them in a Listbox. I got about 80 services on my computer. Now i changed the style too Check box and when the user clicks on a check next too a service it adds it too List Box 2.Private Sub List1_Click()List2.AddItem List1.TextEnd SubBut if the user keeps clicking on the Checkbox it shows up multiple times in ListBox2. ... How can i make it so if the Checkbox is Checked in List1 it adds the Item too List2 but if it gets unchecked it removes the item from List2?Thanks*Notice how theres multiple "Alerter" services in the second List box* Link to comment Share on other sites More sharing options...
Synapse Posted August 17, 2004 Author Share Posted August 17, 2004 oh yea...with this coding, i can get True or False values for wether the service is Started or Stopped using:Service.Startedanyway too make it so if Service.Started is True the Checkbox would be Checked. if its False it would be unchecked..? Link to comment Share on other sites More sharing options...
jcarle Posted August 17, 2004 Share Posted August 17, 2004 You'll want to do something like this:Private Sub List1_Click() Dim isFound As Boolean Dim i As Integer isFound = False For i = 0 To (List2.ListCount - 1) If List1.ListItems(List1.SelectedItem).Checked Then If List2.List(i) = List1.ListItems(List1.SelectedItem).Text Then isFound = True Else If List2.List(i) = List1.ListItems(List1.SelectedItem).Text Then List2.RemoveItem i End If Next If List1.ListItems(List1.SelectedItem).Checked And Not isFound Then List2.AddItem List1.TextEnd Sub Link to comment Share on other sites More sharing options...
Synapse Posted August 17, 2004 Author Share Posted August 17, 2004 You'll want to do something like this:Private Sub List1_Click() Dim isFound As Boolean Dim i As Integer isFound = False For i = 0 To (List2.ListCount - 1) If List1.ListItems(List1.SelectedItem).Checked Then If List2.List(i) = List1.ListItems(List1.SelectedItem).Text Then isFound = True Else If List2.List(i) = List1.ListItems(List1.SelectedItem).Text Then List2.RemoveItem i End If Next If List1.ListItems(List1.SelectedItem).Checked And Not isFound Then List2.AddItem List1.TextEnd Subthanks i'll try it now Link to comment Share on other sites More sharing options...
Synapse Posted August 17, 2004 Author Share Posted August 17, 2004 hmmm getting an error on this line:If List1.ListItems(List1.SelectedItem).Checked Thensaying Method or Data Member not found. *this is Visual Basic 6 by the way*tried to substitute "SelectedItem" for "Seleted" and got "Argument not Optional.*sorry, still a newb too Visual Basic lol*EDIT:Is there a way too make the List box like the attached pic of Msconfig? Link to comment Share on other sites More sharing options...
Synapse Posted August 17, 2004 Author Share Posted August 17, 2004 well, i'm playing around with "ListView" now insted of the normal List... Link to comment Share on other sites More sharing options...
jcarle Posted August 17, 2004 Share Posted August 17, 2004 Not sure for the error. I don't have VB6 in front of me. However, MSDN is your friend. Link to comment Share on other sites More sharing options...
Doggie Posted August 17, 2004 Share Posted August 17, 2004 and if you're lucky like me, MSDN Library on cd Link to comment Share on other sites More sharing options...
Synapse Posted August 17, 2004 Author Share Posted August 17, 2004 Still working with the "ListView" object insted of the normal "List" a bit more complicated but got the gridlines, columns and all that good stuff. Just need too findout how too make it so that when populating the list if "SubItems" is True then check the box in my list, if its false leave it unchecked.Private Sub Command1_Click() Dim Service As Variant Dim i As Integer i = 1 For Each Service In GetObject("winmgmts:").ExecQuery("select * from Win32_Service") ListView1.ListItems.Add i, , Service.DisplayName ListView1.ListItems(i).SubItems(1) = Service.Startedi = 1 + i Next Command1.Enabled = False ListView1.Sorted = TrueEnd Subsomewhat primitive but gets the job done.---Attached Pic---thats my project in testing mode checkin all that crap and yea... Command 1 populates the List, Command 2 Exits, Command 3 Deletes and service from the "ListView" if they are checked... Link to comment Share on other sites More sharing options...
Synapse Posted August 17, 2004 Author Share Posted August 17, 2004 Jcarle, I've been "playin" with the code you gave me and finally got it too "somewhat" work... I changed some of it too:Private Sub ListView1_Click()Dim isFound As BooleanDim i As IntegerisFound = FalseFor i = 0 To (List2.ListCount - 1) If ListView1.SelectedItem.Checked Then If List2.List(i) = ListView1.SelectedItem.Text Then isFound = True Else If List2.List(i) = ListView1.SelectedItem.Text Then List2.RemoveItem i End IfNextIf ListView1.SelectedItem.Checked And Not isFound Then List2.AddItem ListView1.SelectedItemNow when i have the Listview populated and i click on just the checkbox without selecting the actual text it checks but doesnt add it too the list. But when i finally click on the Text it adds it too "List2"Overall, its doing what i wanted, but is there anyway that i can make it to when i click on the checkbox it'll select the current line?Thanks again.*Edit* If push comes too shove i'll probably just add a timer if thats possible. Link to comment Share on other sites More sharing options...
jcarle Posted August 17, 2004 Share Posted August 17, 2004 Perhaps ItemClick (MSDN Documentation) can help you. Link to comment Share on other sites More sharing options...
Synapse Posted August 18, 2004 Author Share Posted August 18, 2004 Perhaps ItemClick (MSDN Documentation) can help you.ahh thanks, i'm also looking at the ItemCheck coding too. its adding items when i click on the check without having it as the Selected Item. Thanks jcarle Link to comment Share on other sites More sharing options...
jcarle Posted August 18, 2004 Share Posted August 18, 2004 Glad I could help. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now