I’ve spent whole 3 days to resolve a problem in my program. I still didn’t do that and therefore I decided to ask here for help.
-My program have TreeView and ListView control. After selecting an item from TreeView, program fills ListView up from database.
-ListView has right-click context menu with options for adding a copy of existing item and deleting an item from ListView and from database itself.
Everything works fine except two things:
1. When I’m deleting a listview item, it is wiped out from the database but it is still shown as a ListView item. If I change selected item from TreeView and come back to the previous one, the item from ListView is deleted. Also, if I’m working in debugging mode, everything’s working fine.
I’ve tried many things to resolve this issue without success.
2. The second problem is related with adding a copy of existing item to the database. It works fine for the first attempt of copying But, if I click new formed item with mouse, I’m getting an error: 3021: Either BOF or EOF is true.. etc etc… I’m not sure why I get this message if I only click on new item which is exactly a copy of an existing item?
Any help would be helpful
rgds
Here's a code which updates ListView from database:
VB Code:
Public Sub UpdateMainLV() 'subroutine updates ListView control from database Dim con33 As ADODB.Connection Dim rs33 As ADODB.Recordset Set con33 = New ADODB.Connection con33.CursorLocation = adUseClient con33.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb" Set rs33 = New ADODB.Recordset frmViewer.ListView1.ListItems.Clear ''============== Dim SQL33 As String SQL33 = "SELECT * FROM base_rec WHERE sub_cat = " & "'" & frmViewer.TreeView1.SelectedItem.Text & "'" & " AND lv_category= " & "'" & frmViewer.TreeView1.SelectedItem.Parent.Text & "' ORDER BY sub_cat DESC;" rs33.Open SQL33, con33, 3, 4 rs33.MoveFirst Dim i As Integer For i = 0 To rs33.RecordCount - 1 Set lvwItem = frmViewer.ListView1.ListItems.Add(1, , rs33.Fields!lv_category) lvwItem.SubItems(1) = rs33.Fields!sub_cat lvwItem.SubItems(2) = rs33.Fields!lvp_name lvwItem.SubItems(3) = rs33.Fields!comment lvwItem.SubItems(4) = rs33.Fields!date rs33.MoveNext Next i rs33.Resync rs33.Close con33.Close Set rs33 = Nothing Set con33 = Nothing frmViewer.ListView1.Refresh
And here's a code which calls this routine :
VB Code:
Private Sub mnulvDelete_click() '<============== BRISI LV ITEM Dim con As ADODB.Connection Dim rs7 As ADODB.Recordset Dim SQL7 As String SQL7 = "SELECT * FROM base_rec WHERE lvp_name='" & CStr(lblSel.Caption) & "';" Set con = New ADODB.Connection con.CursorLocation = adUseClient con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb" Set rs7 = New ADODB.Recordset rs7.Open SQL7, con, 3 , 4 rs7.Delete rs7.Update rs7.Resync rs7.Close Dim indx As Integer Dim lvrows As Integer lvrows = ListView1.ListItems.Count For indx = 1 To lvrows If indx > lvrows Then Exit For If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then ListView1.ListItems.Remove (indx) indx = indx - 1 lvrows = lvrows- 1 End If Next Call frmKV.UpdateMainLV End Sub




Reply With Quote