• Welcome to Valhalla Legends Archive.
 

Removing a User from a listview

Started by AC_Drkan, July 12, 2004, 03:39 PM

Previous topic - Next topic

AC_Drkan

Help?

Private Sub CleanSlateBot1_UserLeaves(ByVal Username As String, ByVal Flags As Long, SimulatedEvent As Boolean)
Username = Replace(Username, "*", "")
On Error Resume Next
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i) = Username Then
ListView1.ListItems.Remove i
End If
Next i
AddChat rtbChat, Username & " has left the channel.1", vbGreen, vbNewLine

End Sub


Dosen't Generate an error nut it instead add another user with the same name instead of deleting it.
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

AC_Drkan

Nvm i think i fixed this

Taken from ETH bot
Private Sub Event_Leave(strUser As String, StrFlag)
On Error Resume Next
   Dim strCount As String
   
   strCount = frmMain.RoomList.ListItems.count
   If Err.Number = 0 Then
   frmMain.RoomList.ListItems.Remove frmMain.RoomList.FindItem(strUser).Index
   End If
 
   addText strUser & " has left the channel" & vbNewLine, ID_COLOR_INFO
   frmMain.text1.text = msChannelName & " (" & frmMain.RoomList.ListItems.count & ")"
   
End Sub
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

AC_Drkan

Quote from: AC_Drkan on July 12, 2004, 03:57 PM
Nvm i think i fixed this

Taken from ETH bot
Private Sub Event_Leave(strUser As String, StrFlag)
On Error Resume Next
   Dim strCount As String
   
   strCount = frmMain.RoomList.ListItems.count
   If Err.Number = 0 Then
   frmMain.RoomList.ListItems.Remove frmMain.RoomList.FindItem(strUser).Index
   End If
 
   addText strUser & " has left the channel" & vbNewLine, ID_COLOR_INFO
   frmMain.text1.text = msChannelName & " (" & frmMain.RoomList.ListItems.count & ")"
   
End Sub


nvm the nvm im lost
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

l)ragon

*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

ChR0NiC

#4
Well you could use a loop like this.


Private Sub CleanSlateBot1_UserLeaves(ByVal Username As String, ByVal Flags As Long, SimulatedEvent As Boolean)
Username = Replace(Username, "*", "")

For i = 1 To ListView1.ListItems.Count
If LCase(ListView1.ListItems(i)) = LCase(Username) Then
ListView1.ListItems.Remove(i)
GoTo ShowMessage
End If
Next i

ShowMessage: 'Jump to this to save time from checking the other users.
AddChat rtbChat, Username & " has left the channel.1", vbGreen, vbNewLine

End Sub


Also your On Error Resume Next might be jumping through an error you are receiving, try removing that and debugging the error.

One other thing, is it adding the users with a * on the listview? Because if it is, your loop won't find a match.

Eli_1

If it's truly a listview, and not a listbox, you should be able to just simply do:


listview1.ListItems.Remove listview1.FindItem(Username).index

BaDDBLooD

Quote from: Eli_1 on August 08, 2004, 08:26 PM
If it's truly a listview, and not a listbox, you should be able to just simply do:


listview1.ListItems.Remove listview1.FindItem(Username).index


Took the words right out of my mouth!
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Adron

Quote from: BaDDBLooD on August 08, 2004, 10:52 PM
Quote from: Eli_1 on August 08, 2004, 08:26 PM
If it's truly a listview, and not a listbox, you should be able to just simply do:


listview1.ListItems.Remove listview1.FindItem(Username).index


Took the words right out of my mouth!

Don't make useless replies - if someone has already given the answer and it's not being disputed by someone else, there's no need to tell everyone that you agree about the answer. If we all did, these topics would all be a dozen pages long in no time, and we don't want that.

Grok

Quote from: Eli_1 on August 08, 2004, 08:26 PM
If it's truly a listview, and not a listbox, you should be able to just simply do:


listview1.ListItems.Remove listview1.FindItem(Username).index


Remember to handle the VB error that will occur if FindItem does not find the name in the ListView and you pass that Index (of a Null object) to the Remove method of ListItems.  In this particular application you are never expecting it, since you will only be removing from the ListView those items which you have added, but half the point of error handlers is for the unexpected, keeping your program from crashing ungracefully.

AC_Drkan

ThY ALL!!!!
fixed the removing and adding, look:

Private Sub CleanSlateBot1_UserLeaves(ByVal Username As String, ByVal Flags As Long, SimulatedEvent As Boolean)
Username = Replace(Username, "*", "")
'Code For Removing a User From a List View Goes Here
   Username = Replace(Username, "*", vbNullString)
   On Error Resume Next
   lvChannel.ListItems.Remove lvChannel.FindItem(Username).Index
   lblChannel.Caption = Channel & " (" & lvChannel.ListItems.Count & ")"

   If mnuToggleJLMessages.Checked = True Then
       AddChat rtbChat, Username & " has left the channel.", vbGreen, vbNewLine
   End If
End Sub
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

ChR0NiC

#10
Might want to do
lvChannel.ListItems.Refresh after the removal because sometimes things look a little tacky and bits and pieces of icons get stuck, also I notice you are using CSB, and I recommend you actually use my BNLS Logon Control, because it can logon W3 and has a few extra features, check it out :)

Eli_1

Quote from: ChR0NiC on August 20, 2004, 12:44 PM
Might want to do
lvChannel.ListItems.Refresh after the removal because sometimes things look a little tacky and bits and pieces of icons get stuck, also I notice you are using CSB, and I recommend you actually use my BNLS Logon Control, because it can logon W3 and has a few extra features, check it out :)

IIRC, CSB can log on W3 just fine.
By the way Drkan, On Error Resume Next is a very poor way of "handling" errors.

ChR0NiC

Quote from: Eli_1 on August 20, 2004, 01:33 PM
IIRC, CSB can log on W3 just fine.

It doesn't work correctly anymore, it gets a run time error subscript out of range error when logging on W3, which means it needs to be updated. So you are incorrect Eli >:(

AC_Drkan

Quote from: Eli_1 on August 20, 2004, 01:33 PM
Quote from: ChR0NiC on August 20, 2004, 12:44 PM
Might want to do
lvChannel.ListItems.Refresh after the removal because sometimes things look a little tacky and bits and pieces of icons get stuck, also I notice you are using CSB, and I recommend you actually use my BNLS Logon Control, because it can logon W3 and has a few extra features, check it out :)

:'(
i know but thats so much easier

IIRC, CSB can log on W3 just fine.
By the way Drkan, On Error Resume Next is a very poor way of "handling" errors.
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.