OminousVortex
New member
- Joined
- Mar 1, 2013
- Messages
- 2
- Programming Experience
- 3-5
I have a form in my program that has a listview on it. I am able to add data to the listview without any problems. The issue I have is when I try to add/delete an item from the database. The add/delete works properly on the database side. However, when I call the routine to fill the listview again, it doesn't update until I reselect a date from the calendar. When I click on the date in the calendar, the listview fills again like planned and the data has been added/deleted from the list. I have looked and looked but have not been able to find a resolution for this. Any help would be appreciated.
I created another simple form to try to make it easier to understand. Here is the code:
Public Class Form1
Dim sngSelectedDaily As Single
Dim dteDateSelected As Date
Private Sub List_Load(ByVal dteViewDate As Date)
Dim strGetListData As String
Dim oleDbCmdGetListData As OleDb.OleDbCommand
Dim dtrGetListData As OleDb.OleDbDataReader
'MsgBox(ListView1.Items.Count.ToString)
ListView1.Clear()
''Set view property
ListView1.View = View.Details
ListView1.GridLines = True
ListView1.FullRowSelect = True
strGetListData = "Select tblDaily.ProjectID, tblDaily.TaskID, tblDaily.TaskDesc, tblDaily.EntryDate, tblDaily.TimeSpent, tblDaily.Phase, tblProjects.Project, tblJKKPhases.PhaseName, tblDaily.Abnormal FROM (tblProjects INNER JOIN tblDaily ON tblProjects.ProjectID = tblDaily.ProjectID) LEFT JOIN tblJKKPhases ON tblDaily.Phase = tblJKKPhases.PhaseID Where (tblDaily.EntryDate = " & "#" & dteDateSelected & "#)" & " Order By TaskID"
Try
oleDbCmdGetListData = New OleDb.OleDbCommand(strGetListData, GetAccessConn(1))
dtrGetListData = oleDbCmdGetListData.ExecuteReader()
''Add column header
ListView1.Columns.Add("ProjectID", 0, HorizontalAlignment.Center)
ListView1.Columns.Add("TaskID", 0, HorizontalAlignment.Center)
ListView1.Columns.Add("Description", 250, HorizontalAlignment.Left)
ListView1.Columns.Add("Entry Date", 95, HorizontalAlignment.Center)
ListView1.Columns.Add("Time", 50, HorizontalAlignment.Center)
ListView1.Columns.Add("PhaseNumber", 0, HorizontalAlignment.Center)
ListView1.Columns.Add("Project", 250, HorizontalAlignment.Left)
ListView1.Columns.Add("Phase", 220, HorizontalAlignment.Left)
ListView1.Columns.Add("Type", 50, HorizontalAlignment.Center)
While dtrGetListData.Read
'Add items in the listview
Dim arr(8) As String
Dim itm As ListViewItem
'Add first item
arr(0) = dtrGetListData(0)
arr(1) = dtrGetListData(1)
arr(2) = dtrGetListData(2)
arr(3) = dtrGetListData(3)
arr(4) = dtrGetListData(4)
arr(5) = dtrGetListData(5)
arr(6) = dtrGetListData(6)
arr(7) = GetNullValue(dtrGetListData(7))
If dtrGetListData(8) = False Then
arr(8) = "N"
Else
arr(8) = "A"
End If
arr(8) = dtrGetListData(8)
itm = New ListViewItem(arr)
ListView1.Items.Add(itm)
End While
'dtrGetListData.Close()
dtrGetListData.Dispose()
oleDbCmdGetListData.Dispose()
GetAccessConn(2)
'MsgBox(ListView1.Items.Count.ToString)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ListView1_Click(sender As Object, e As System.EventArgs) Handles ListView1.Click
sngSelectedDaily = ListView1.SelectedItems(0).SubItems(1).Text
End Sub
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As System.EventArgs) Handles DateTimePicker1.ValueChanged
dteDateSelected = FormatDateTime(DateTimePicker1.Value, DateFormat.ShortDate)
Call List_Load(dteDateSelected)
End Sub
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Call DeleteData()
End Sub
Private Sub DeleteData()
Dim strDeleteDaily As String
Dim oleDbCmdDeleteDaily As OleDb.OleDbCommand
Dim dtrDeleteDaily As OleDb.OleDbDataReader
strDeleteDaily = "DELETE FROM tblDaily Where tblDaily.TaskID = " & sngSelectedDaily
Try
oleDbCmdDeleteDaily = New OleDb.OleDbCommand(strDeleteDaily, GetAccessConnB(1))
dtrDeleteDaily = oleDbCmdDeleteDaily.ExecuteReader()
Catch ex As Exception
MsgBox(ex.Message)
End Try
'MsgBox(cboActivity.SelectedValue.ToString)
dtrDeleteDaily.Dispose()
oleDbCmdDeleteDaily.Dispose()
GetAccessConnB(2)
Call List_Load(dteDateSelected) 'fill list box with entries for selected date
End Sub
End Class
I created another simple form to try to make it easier to understand. Here is the code:
Public Class Form1
Dim sngSelectedDaily As Single
Dim dteDateSelected As Date
Private Sub List_Load(ByVal dteViewDate As Date)
Dim strGetListData As String
Dim oleDbCmdGetListData As OleDb.OleDbCommand
Dim dtrGetListData As OleDb.OleDbDataReader
'MsgBox(ListView1.Items.Count.ToString)
ListView1.Clear()
''Set view property
ListView1.View = View.Details
ListView1.GridLines = True
ListView1.FullRowSelect = True
strGetListData = "Select tblDaily.ProjectID, tblDaily.TaskID, tblDaily.TaskDesc, tblDaily.EntryDate, tblDaily.TimeSpent, tblDaily.Phase, tblProjects.Project, tblJKKPhases.PhaseName, tblDaily.Abnormal FROM (tblProjects INNER JOIN tblDaily ON tblProjects.ProjectID = tblDaily.ProjectID) LEFT JOIN tblJKKPhases ON tblDaily.Phase = tblJKKPhases.PhaseID Where (tblDaily.EntryDate = " & "#" & dteDateSelected & "#)" & " Order By TaskID"
Try
oleDbCmdGetListData = New OleDb.OleDbCommand(strGetListData, GetAccessConn(1))
dtrGetListData = oleDbCmdGetListData.ExecuteReader()
''Add column header
ListView1.Columns.Add("ProjectID", 0, HorizontalAlignment.Center)
ListView1.Columns.Add("TaskID", 0, HorizontalAlignment.Center)
ListView1.Columns.Add("Description", 250, HorizontalAlignment.Left)
ListView1.Columns.Add("Entry Date", 95, HorizontalAlignment.Center)
ListView1.Columns.Add("Time", 50, HorizontalAlignment.Center)
ListView1.Columns.Add("PhaseNumber", 0, HorizontalAlignment.Center)
ListView1.Columns.Add("Project", 250, HorizontalAlignment.Left)
ListView1.Columns.Add("Phase", 220, HorizontalAlignment.Left)
ListView1.Columns.Add("Type", 50, HorizontalAlignment.Center)
While dtrGetListData.Read
'Add items in the listview
Dim arr(8) As String
Dim itm As ListViewItem
'Add first item
arr(0) = dtrGetListData(0)
arr(1) = dtrGetListData(1)
arr(2) = dtrGetListData(2)
arr(3) = dtrGetListData(3)
arr(4) = dtrGetListData(4)
arr(5) = dtrGetListData(5)
arr(6) = dtrGetListData(6)
arr(7) = GetNullValue(dtrGetListData(7))
If dtrGetListData(8) = False Then
arr(8) = "N"
Else
arr(8) = "A"
End If
arr(8) = dtrGetListData(8)
itm = New ListViewItem(arr)
ListView1.Items.Add(itm)
End While
'dtrGetListData.Close()
dtrGetListData.Dispose()
oleDbCmdGetListData.Dispose()
GetAccessConn(2)
'MsgBox(ListView1.Items.Count.ToString)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ListView1_Click(sender As Object, e As System.EventArgs) Handles ListView1.Click
sngSelectedDaily = ListView1.SelectedItems(0).SubItems(1).Text
End Sub
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As System.EventArgs) Handles DateTimePicker1.ValueChanged
dteDateSelected = FormatDateTime(DateTimePicker1.Value, DateFormat.ShortDate)
Call List_Load(dteDateSelected)
End Sub
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Call DeleteData()
End Sub
Private Sub DeleteData()
Dim strDeleteDaily As String
Dim oleDbCmdDeleteDaily As OleDb.OleDbCommand
Dim dtrDeleteDaily As OleDb.OleDbDataReader
strDeleteDaily = "DELETE FROM tblDaily Where tblDaily.TaskID = " & sngSelectedDaily
Try
oleDbCmdDeleteDaily = New OleDb.OleDbCommand(strDeleteDaily, GetAccessConnB(1))
dtrDeleteDaily = oleDbCmdDeleteDaily.ExecuteReader()
Catch ex As Exception
MsgBox(ex.Message)
End Try
'MsgBox(cboActivity.SelectedValue.ToString)
dtrDeleteDaily.Dispose()
oleDbCmdDeleteDaily.Dispose()
GetAccessConnB(2)
Call List_Load(dteDateSelected) 'fill list box with entries for selected date
End Sub
End Class