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
Many thanksCode: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




Reply With Quote
