Solved

Visual basic how to remove selected items listview control.

Posted on 2004-04-20
23
18,211 Views
Last Modified: 2011-08-18
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
Comment
Question by:bluedragon99
  • 11
  • 4
  • 2
  • +3
23 Comments
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
Using SetAlertsViewer.ListItems.Remove (SetAlertsViewer.SelectedItem)
 

I get invalid key
0
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
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
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
SetAlertsViewer.ListItems.Remove (SetAlertsViewer.ListIndex)
0
 
LVL 3

Expert Comment

by:elantra
Comment Utility
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
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
on .Listindex method or data member not found error.........
0
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
.ListIndex doesn't seem to exist at all...This should be easy don't know why I can't figure it out.
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
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
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
I am getting constant method or data membor not found on SelectedIndexCollection
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
using this MsgBox SetAlertsViewer.SelectedIndexCollection
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
its a collection you need to do a for each

for each aIndex in SetAlertsViewer.SelectedIndexCollection
0
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
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
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
I don't think I building the collection index right...
0
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
This works for an individual item

SetAlertsViewer.ListItems.Remove SetAlertsViewer.SelectedItem.Index
0
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility
ListView.SelectedIndexCollection is for .NET
0
 
LVL 8

Accepted Solution

by:
rajaloysious earned 500 total points
Comment Utility
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
 
LVL 1

Expert Comment

by:issamtaher
Comment Utility
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
 
LVL 8

Expert Comment

by:rajaloysious
Comment Utility
hi issamtaher...........................

hmmmmmmmmmmmmmmmm...

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

hopefully the author would give the poins to me ................
0
 
LVL 1

Expert Comment

by:issamtaher
Comment Utility
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
 
LVL 1

Expert Comment

by:curt_henderson
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 70
object oriented javascript web form 8 70
parentbit challenge 3 50
word0 challenge 3 55
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now