Results 1 to 7 of 7

Thread: [Resolved][2005] removing an item from a list view box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    166

    Resolved [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?
    Last edited by HelpLaura; Apr 22nd, 2007 at 04:10 PM. Reason: Resolved

  2. #2
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    Re: [2005] removing an item from a list view box

    Hi, Try this in your button click sub

    vb Code:
    1. Dim indexes As ListView.SelectedIndexCollection = _
    2.              Me.ListView1.SelectedIndices
    3.         Dim index As Integer
    4.  
    5.         For Each index In indexes
    6.             Me.ListView1.Items(index).Remove()
    7.             Me.ListView1.Refresh()
    8.         Next

    Fishy

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    166

    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:
    1. Private Sub btn_remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_remove.Click
    2.  
    3.         Dim indexes As ListBox.SelectedIndexCollection = Me.ListBox1.SelectedIndices
    4.         Dim index As Integer
    5.  
    6.         For Each index In indexes
    7.             Me.ListBox1.Items(index).Remove()
    8.             Me.ListBox1.Refresh()
    9.         Next
    10.  
    11.     End Sub

    Any ideas?

  4. #4
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    166

    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.

  6. #6
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem)
    3.     End Sub

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    166

    Re: [2005] removing an item from a list view box

    This works a treat thanks for your help, it is much appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width