Results 1 to 6 of 6

Thread: Remove item from listbox populated from query

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2013
    Posts
    40

    Remove item from listbox populated from query

    The below code is populating a listbox form a data query when a node with a specific string value is clicked on in a treeview. The items that are displayed in the listbox can then be double clicked and the underlying file is copied to the directory of the tree node and the text added as a child node.

    Is it possible to then remove the object text from the listbox on the double click and keep it from being re-added if the original node is reclicked (The nodes are jobs and the listbox items reports and there could be multiple job nodes that have the same report requirement)?

    Removing items from the database is not an option

    Code:
    Private Sub tvProgress_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles tvProgress.AfterSelect
            Try
                Dim da As New OleDb.OleDbDataAdapter("", "")
                Dim dt As New DataTable
                Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Me.aClients & ""
                Dim n As Integer
    
    
                For n = 0 To UBound(AllDetails)
    
                    If tvProgress.Nodes.Count = 0 Then Exit Sub
    
                    If AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps = e.Node.Text Then
    
                        Dim eSearch As String = AllDetails(n).uCode
                        Dim fSearch As String = AllDetails(n).uOps
    
                        da.SelectCommand.Connection.ConnectionString = conn
                        da.SelectCommand.CommandText = "SELECT Documents.DocName FROM Documents WHERE (Documents.UnitCode = ?) AND (Documents.OpName = ?) AND Documents.Required = True ORDER BY DocName"
                        da.SelectCommand.Parameters.AddWithValue("@p1", eSearch)
                        da.SelectCommand.Parameters.AddWithValue("@p2", fSearch)
                        da.Fill(dt)
                        dt.Rows.Add("Add Additional Requirement")
    
                        lstRequired.DataSource = dt
                        lstRequired.DisplayMember = StrConv("DocName", VbStrConv.ProperCase)
                        lstRequired.Refresh()
    
                        Dim dl As DataTable = CType(lstRequired.DataSource, DataTable)
                        Using sR = New IO.StreamReader(tFiles & UCase("ProgExcluded.txt"))
                            While (sR.Peek() > -1)
                                Dim rows() = dl.Select("DocName = '" + sR.ReadLine + "'")
                                For Each row In rows
                                    row.Delete()
                                Next
                                dl.AcceptChanges()
                            End While
                        End Using
    
                    End If
                Next
    
                Exit Sub
    
                lstRequired.DataSource = Nothing
                lstRequired.DataBindings.Clear()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
        End Sub
    Many thanks
    Last edited by MarkGB; Mar 16th, 2014 at 05:11 PM. Reason: Spelling

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Remove item from listbox populated from query

    If you remove the item from the datatable, the change will be reflected in the listbox

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2013
    Posts
    40

    Re: Remove item from listbox populated from query

    If i remove the item from the datatable will it still be available if selecting a different node?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Remove item from listbox populated from query

    As for readding, you'll need to change your select query so it filters out any items you've previously removed.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Remove item from listbox populated from query

    The item won't be removed from the underlying database

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2013
    Posts
    40

    Re: Remove item from listbox populated from query

    Thanks, the removing from the original database is the bit i'm more concerned with not doing!

    I'll see what i can come up with

Tags for this Thread

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