|
-
Sep 11th, 2012, 06:34 AM
#1
Thread Starter
Fanatic Member
Why does this not work (Finding item in listview)
So guys I'm using this code to find if there is any items in a listview
Code:
Dim i As Long, ItemFound As Boolean
For i = 1 To Form9.ListView1.ListItems.Count
If Form9.ListView1.ListItems(i).SubItems(2) = Format$(Now, "dd/mm/yyyy") And Form9.ListView1.ListItems(i).SubItems(3) >= "09:00" And Form9.ListView1.ListItems(i).SubItems(3) <= "09:29" Then
Form9.ListView1.ListItems(i).Selected = True
ItemFound = True
Exit For
Else
ItemFound = False
End If
Next i
If ItemFound = True Then
Combo1.Visible = True
Combo1.Text = Form9.ListView1.SelectedItem
Combo1.AddItem (Form9.ListView1.SelectedItem)
between the times of 09:00 and 09:30
if so, I want it to add them to combo1.text
for some reason at the moment the if item found code does not work as combo1 does not become visible,
Any ideas why?
Thanks,
Jamie
-
Sep 11th, 2012, 07:01 AM
#2
Re: Why does this not work (Finding item in listview)
Have you single-stepped through your loop, if your code is really finding an item according to your criteria?
The only reason your combo-box doesn't show up, is if ItemFound is False
-
Sep 11th, 2012, 07:24 AM
#3
Thread Starter
Fanatic Member
Re: Why does this not work (Finding item in listview)
Hi mate, it's started to work, how ever only finds one item. How can i make it check if there is more than one and if so add it in on form load?
Thanks
Jamie
-
Sep 11th, 2012, 07:26 AM
#4
Thread Starter
Fanatic Member
Re: Why does this not work (Finding item in listview)
Hi mate, it's started to work, how ever only finds one item. How can i make it check if there is more than one and if so add it in on form load?
Thanks
Jamie
-
Sep 11th, 2012, 07:55 AM
#5
Re: Why does this not work (Finding item in listview)
vb Code:
Dim i As Long, ItemFound As Boolean For i = 1 To Form9.ListView1.ListItems.Count If Form9.ListView1.ListItems(i).SubItems(2) = Format$(Now, "dd/mm/yyyy") And Form9.ListView1.ListItems(i).SubItems(3) >= "09:00" And Form9.ListView1.ListItems(i).SubItems(3) <= "09:29" Then Form9.ListView1.ListItems(i).Selected = True Combo1.Visible = True 'If at least one item is found Combo1.Text = Form9.ListView1.SelectedItem Combo1.AddItem (Form9.ListView1.SelectedItem) Else ItemFound = False End If Next i
-
Sep 11th, 2012, 08:36 AM
#6
Thread Starter
Fanatic Member
Re: Why does this not work (Finding item in listview)
Thanks mate, that works however only lists one item found in the combo box, how do i make it display each result found and then add it to the combo box?
Thanks,
Jamie
-
Sep 11th, 2012, 08:39 AM
#7
Re: Why does this not work (Finding item in listview)
Could you post your contents of your ListView?
Is your Combobox in Dropdown-Style?
-
Sep 11th, 2012, 09:18 AM
#8
Thread Starter
Fanatic Member
Re: Why does this not work (Finding item in listview)
So the contents of the listview are :
Joe Bloggs | 11/09/2012 | 09:15
Joe Bloggs1 | 11/09/2012 | 09:22
Joe Bloggs2 | 11/09/2012 | 10:15
At the moment it only display the first one rather than the first 2 (as they are both within 09:00 and 09:30)
And yes it is dropdown.
Cheers
-
Sep 11th, 2012, 09:47 AM
#9
Re: Why does this not work (Finding item in listview)
And you're sure, that the second item is not in the dropdown-part of the combo-box?
btw: Delete Line 6 in my sample-code above. Maybe you'll see something
-
Sep 11th, 2012, 09:49 AM
#10
Re: Why does this not work (Finding item in listview)
Rather than
Code:
Combo1.Text = Form9.ListView1.SelectedItem
Combo1.AddItem (Form9.ListView1.SelectedItem)
Try
Code:
Combo1.Text = Form9.ListView1.ListItems(i).SubItems(3)
Combo1.AddItem (Form9.ListView1.ListItems(i).SubItems(3))
-
Sep 11th, 2012, 10:11 AM
#11
Thread Starter
Fanatic Member
Re: Why does this not work (Finding item in listview)
Nope only showing the first one
-
Sep 11th, 2012, 10:31 AM
#12
Re: Why does this not work (Finding item in listview)
Then there is something wrong with your entry in the ListView.
If your If-Clause finds the first entry, but not the second one, then something's wrong with the entry and not the code.
-
Sep 11th, 2012, 10:39 AM
#13
Thread Starter
Fanatic Member
Re: Why does this not work (Finding item in listview)
It's finding it, but its only adding one item to the combo rather than all of them, the code works on another form it basically shows a form when its found, but when adding it to the combo it only shows one entry, but its all defo in the listview.
-
Sep 11th, 2012, 11:10 AM
#14
Re: Why does this not work (Finding item in listview)
Try this
vb Code:
Dim i As Long, ItemFound As Boolean For i = 1 To Form9.ListView1.ListItems.Count If Form9.ListView1.ListItems(i).SubItems(2) = Format$(Now, "dd/mm/yyyy") And Form9.ListView1.ListItems(i).SubItems(3) >= "09:00" And Form9.ListView1.ListItems(i).SubItems(3) <= "09:29" Then Combo1.Visible = True 'If at least one item is found Combo1.Text = Form9.ListView1.ListItems(i).Text Combo1.AddItem (Form9.ListView1.ListItems(i).Text) End If Next i
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|