Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual basic how to remove selected items listview control.

Posted on 2004-04-20
23
Medium Priority
?
18,477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 4
  • 2
  • +3
23 Comments
 
LVL 1

Author Comment

by:bluedragon99
ID: 10872576
Using SetAlertsViewer.ListItems.Remove (SetAlertsViewer.SelectedItem)
 

I get invalid key
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10872627
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
ID: 10872706
SetAlertsViewer.ListItems.Remove (SetAlertsViewer.ListIndex)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Expert Comment

by:elantra
ID: 10872756
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
ID: 10872758
on .Listindex method or data member not found error.........
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10872803
.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
ID: 10872847
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
ID: 10872887
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
ID: 10873023
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
ID: 10873030
I am getting constant method or data membor not found on SelectedIndexCollection
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10873035
using this MsgBox SetAlertsViewer.SelectedIndexCollection
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10873077
its a collection you need to do a for each

for each aIndex in SetAlertsViewer.SelectedIndexCollection
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10873253
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
ID: 10873348
I don't think I building the collection index right...
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10873556
This works for an individual item

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

Author Comment

by:bluedragon99
ID: 10873566
ListView.SelectedIndexCollection is for .NET
0
 
LVL 8

Accepted Solution

by:
rajaloysious earned 2000 total points
ID: 10875319
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
ID: 10877588
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
ID: 10877675
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
ID: 10877871
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
ID: 10893355
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

618 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