[Resolved][2005] removing an item from a list view box
Hi
my program builds SQL queries for users with no SQL knowledge. They select a field then a operator and then enter criteria. on clicking add, it adds the criteria to the listview in the form field = criteria.
If the user selects a row in the listview i want there to be a remove button so that it removes this value from the list view.
Can anyone help me do this?
Re: [2005] removing an item from a list view box
Hi, Try this in your button click sub
vb Code:
Dim indexes As ListView.SelectedIndexCollection = _
Me.ListView1.SelectedIndices
Dim index As Integer
For Each index In indexes
Me.ListView1.Items(index).Remove()
Me.ListView1.Refresh()
Next
Fishy
Re: [2005] removing an item from a list view box
thanks for your reply.
I apologise, its a listbox rather than a list view box, but i tried the following code however there is an error on the remove line of
"Overload resolution failed because no accessible 'Remove' accepts this number of arguments."
vb Code:
Private Sub btn_remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_remove.Click
Dim indexes As ListBox.SelectedIndexCollection = Me.ListBox1.SelectedIndices
Dim index As Integer
For Each index In indexes
Me.ListBox1.Items(index).Remove()
Me.ListBox1.Refresh()
Next
End Sub
Any ideas?
Re: [2005] removing an item from a list view box
Does your listbox has its multple row select ptoperty set to true or it is a single row select? Are you going to have multiple-same sql statments in the listbox?
Re: [2005] removing an item from a list view box
thanks for your reply.
I don't see the property that you are refering to. My list box just contain the users input.
The only property i see similar to the one you mention is selection mode, and this is set to one.
The list box doesn't build the actual sql statement until an ok button is pressed. It just stores the criteria ready for the SQL statement creation.
So the remove button just removes a criteria the user no longer wants to add the the statement.
Re: [2005] removing an item from a list view box
Ok yes, i just named the property very general way but that is what I wanted to know. You can use only this one line to remove the selected item from the control.
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem)
End Sub
Re: [2005] removing an item from a list view box
This works a treat thanks for your help, it is much appreciated.