ZeroEffect
Junior Contributor
What I'm doing is taking a list of items based on day of the week and adding it to a new Listview. I am having Two problems.
Problem one:
while the progam loads I load one listview from a file then scan items in that listview and add the ones i want to a new listview as described above. But It doesn't work. My band aide cure was to add a time and delay the event by 1 millisecond. Now the second list loads.
Problem Two:
In the second listview I loop through the first column comparing it's data to the current time and if the time in the listview is greater than the current time exit the sub. But I have the same problem as above nothing gets selected, event if I time delay it.
If either sub is run after the form is completly loaded the work perfect.
Any thoughts this has me banging my head against the wall.
Thanks for your help
ZeroEffect
Here is the code
Problem one:
while the progam loads I load one listview from a file then scan items in that listview and add the ones i want to a new listview as described above. But It doesn't work. My band aide cure was to add a time and delay the event by 1 millisecond. Now the second list loads.
Problem Two:
In the second listview I loop through the first column comparing it's data to the current time and if the time in the listview is greater than the current time exit the sub. But I have the same problem as above nothing gets selected, event if I time delay it.
If either sub is run after the form is completly loaded the work perfect.
Any thoughts this has me banging my head against the wall.
Thanks for your help
ZeroEffect
Here is the code
Visual Basic:
Public Sub NextTimedEvent()
On Error Resume Next
Dim TimeListDay As ListView.SelectedListViewItemCollection = MainForm.PlayListView(8).SelectedItems
Dim SelectedTime As ListViewItem
Dim itm As ListViewItem
Dim I
Dim strDay As String
Dim CurrentDayStr As String
Dim temp As Integer
MainForm.PlayListView(9).Items.Clear()
CurrentDayStr = Date.Today.DayOfWeek.ToString
temp = 1
Do
MainForm.PlayListView(8).Items(temp - 1).Selected = True
For Each SelectedTime In TimeListDay 'Here is where the error happens when the sub is run before the from is loaded --- SelectedTime = nothing
strDay = SelectedTime.SubItems(2).Text
If strDay = CurrentDayStr Then
itm = MainForm.PlayListView(9).Items.Add(SelectedTime.Text)
itm.SubItems.Add(SelectedTime.SubItems(1).Text)
itm.SubItems.Add(SelectedTime.SubItems(2).Text)
itm.SubItems.Add(SelectedTime.SubItems(3).Text)
End If
Next
temp = temp + 1
Loop Until temp > MainForm.PlayListView(8).Items.Count
MainForm.PlayListView(8).Items(0).Selected = True
If LVR = 1 Then 'Using same timer controll
NextInList()
Else
MainForm.Timer5.Enabled = True
End If
End Sub
Public Sub NextInList()
Dim TimeListDay As ListView.SelectedListViewItemCollection = MainForm.PlayListView(9).SelectedItems
Dim SelectedTime As ListViewItem
Dim strtime As Date
Dim inttime As Integer
Dim CurrentTimeStr As String
Dim CurrentTimeInt As Integer
Dim temp As Integer
CurrentTimeStr = Replace(Format(Now(), "HH:mm"), ":", "")
CurrentTimeInt = CurrentTimeStr
temp = 1
Do
MainForm.PlayListView(9).Items(temp - 1).Selected = True
For Each SelectedTime In TimeListDay 'Here is where the error happens when the sub is run before the from is loaded --- SelectedTime = nothing
strtime = SelectedTime.Text
inttime = Replace(Format(strtime, "HH:mm"), ":", "")
If inttime > CurrentTimeInt Then
'Add Info to Label
Exit Sub
Else
SelectedTime.Checked = True
SelectedTime.ForeColor = System.Drawing.Color.Gray
SelectedTime.Font = New Font(SelectedTime.Font, FontStyle.Strikeout)
End If
Next
temp = temp + 1
Loop Until temp > MainForm.PlayListView(9).Items.Count
End Sub