Solved

Visual basic how to remove selected items listview control.

Posted on 2004-04-20
23
18,259 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mapShare challenge 13 107
Arduino EDI - Programming language 3 94
Microsoft C++ code failing in executable that worked 9 98
Recommendation vb6 to vb.net or others 14 149
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is an explanation of a simple data model to help parse a JSON feed
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

777 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