[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 18527
  • Last Modified:

Visual basic how to remove selected items listview control.

Hello,

I have this code for a vb6 listview control, how would I add a button to remove the user selected item.  I have tried the usual selected items but it doesn't seem to work. Working code if possible.

Private Sub Command2_Click()

Set itmx = SetAlertsViewer.ListItems.Add(, , "")
 itmx.SubItems(1) = RuleBox.Text
 itmx.SubItems(2) = OperandBox.Text

end sub
0
bluedragon99
Asked:
bluedragon99
  • 11
  • 4
  • 2
  • +3
1 Solution
 
bluedragon99Author Commented:
Using SetAlertsViewer.ListItems.Remove (SetAlertsViewer.SelectedItem)
 

I get invalid key
0
 
bluedragon99Author Commented:
As a second question on listview is there an event that fires if a specific column is clicked? (to allow sorting for that column?)
0
 
KavarCommented:
SetAlertsViewer.ListItems.Remove (SetAlertsViewer.ListIndex)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
elantraCommented:
Answer to question 2 is no (at least that I'm aware of).  But I believe there is way you can capture the mouse position within the click event and sort each column corresponding to the x,y coordinates of the mouse click within the control.
0
 
bluedragon99Author Commented:
on .Listindex method or data member not found error.........
0
 
bluedragon99Author Commented:
.ListIndex doesn't seem to exist at all...This should be easy don't know why I can't figure it out.
0
 
KavarCommented:
ListIndex is the ordinal number of the currently selected item is a list box...

2 things...

1.)  Is this a list box

2.)  Is something Really selected?
0
 
KavarCommented:
read Kavar READ!!!!

ListView.SelectedIndexCollection
Returns the collection of selected items

When the MultiSelect property is set to true, this property returns a collection containing the indexes of all items that are selected in the ListView. For a single-selection ListView, this property returns a collection containing a single element containing the index of the only selected item in the ListView. For more information on the tasks that can be performed with the items in the collection, see ListView.SelectedIndexCollection.

If you want to obtain a collection of the items that are selected in the ListView control, instead of the index positions of the items that are selected, use the SelectedItems property.

0
 
bluedragon99Author Commented:
Do I need to set the "" to an index var such as i that builds every time this is run from button clicking?


Private Sub Command2_Click()

 Set itmx = SetAlertsViewer.ListItems.Add(, , "")
 itmx.SubItems(1) = RuleBox.Text
 itmx.SubItems(2) = OperandBox.Text

end sub
0
 
bluedragon99Author Commented:
I am getting constant method or data membor not found on SelectedIndexCollection
0
 
bluedragon99Author Commented:
using this MsgBox SetAlertsViewer.SelectedIndexCollection
0
 
KavarCommented:
its a collection you need to do a for each

for each aIndex in SetAlertsViewer.SelectedIndexCollection
0
 
bluedragon99Author Commented:
I'm not getting anywhere here.. This is the addition code to add items.  First thing how do I set the index to allow the collection to work? do I need to build a variable every time they click it increments the index value?  Second I'm still lost on the exact syntax on how to view a specific item in the collection, I have used them before but the syntax seems different here.  Sorry def not a vb pro yet..

Private Sub Command2_Click()

 Set itmx = SetAlertsViewer.ListItems.Add(, , "")
 itmx.SubItems(1) = RuleBox.Text
 itmx.SubItems(2) = OperandBox.Text

end sub
0
 
bluedragon99Author Commented:
I don't think I building the collection index right...
0
 
bluedragon99Author Commented:
This works for an individual item

SetAlertsViewer.ListItems.Remove SetAlertsViewer.SelectedItem.Index
0
 
bluedragon99Author Commented:
ListView.SelectedIndexCollection is for .NET
0
 
rajaloysiousCommented:
The following code works fine in VB6 for me. Great and Fine.
Use SetAlertsViewer.ListItems.Remove (SetAlertsViewer.SelectedItem.Index)

Private Sub Form_Load()
Dim i As Integer
For i = 1 To 10
    Set itmx = SetAlertsViewer.ListItems.Add(, , "")
 itmx.SubItems(1) = CStr(i) & "111aA"
 itmx.SubItems(2) = CStr(i) & "222asdad"
 itmx.SubItems(3) = CStr(i) & "333asdad"
' itmx.SubItems(4) = CStr(i) & "asdad"
 Next
End Sub
Private Sub Command1_Click()
 
    SetAlertsViewer.ListItems.Remove (SetAlertsViewer.SelectedItem.Index)

End Sub
0
 
issamtaherCommented:
hi  bluedragon99


did you try this code :

  i = ListView1.SelectedItem.Index;
  ListView1.ListItems.Remove (i)

or maybe i dont understand you..!
sory if I.

issam
0
 
rajaloysiousCommented:
hi issamtaher...........................

hmmmmmmmmmmmmmmmm...

knowingly or unknowingly you have replicatied my answer...-)

hopefully the author would give the poins to me ................
0
 
issamtaherCommented:
hi  rajaloysious
sory ..!
i did not read your answer.

and i do not want the point
just help the bluedragon99 to get answer.

sory agin.
0
 
curt_hendersonCommented:
Hey bluedragon99

If you want to delete multiple selections:
   MultiSelect = True
If you want to select a whole row at once:
  FullRowSelect = True

To delete multiple selections do this:
  Dim index As Integer
  For index = SetAlertsViewer.ListItems.Count To 1 Step -1
    If SetAlertsViewer.ListItems(index).Selected Then
        SetAlertsViewer.ListItems.Remove (index)
    End If
  Next

To view the contents or manipulate an item do this:
    Dim itmx As ListItem
    Set itmx = SetAlertsViewer.SelectedItem
    MsgBox CStr(itmx.SubItems(1))
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 11
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now