|
-
August 5th, 2002, 12:38 PM
#1
urgent ListView problem
Hi folks,
I have a question on listview report view. I am using a listview (report view) in my program. I wanna add items and fields to the listview after the selected row if it is not empty or else I will append to the end of the existing list in the listview; however I have trouble to identity the selected row in the listview. Somehow, the selected row always returns "1" even I did not select row in the list. I use "myListView.selectedItem.index" to check it. And it also returns on an error while the list is empty. Does anyone know how to check whether the user has selected any item, and if so, which one is the selected item?
Thank you very much and I am really appreciated!
-
August 5th, 2002, 12:57 PM
#2
.SELECTEDITEM should return you the currently selected item (if MULTISELECT is disabled) or the first selected item (if MULTISELECT is enabled). If you list is empty, .SELECTEDITEM is NOTHING and that should be your condition for checking if anything is selected.
-Cool Bizs
-
August 5th, 2002, 01:08 PM
#3
my listView enables multi-selection, and so it always returns 1 when there is no selection made. Even there are items in the list, if no selection is made, .SelectItem returns Nothing too. How can I check whether the returned value for .SelectItem is Nothing? I used IsNull() or IsEmpty(), but both of them do not work!
Thank you for ur help!
-
August 5th, 2002, 01:24 PM
#4
If ListView1.SelectedItem is Nothing then
msgbox "Nothing is selected"
else
msgbox "Got the first one!"
end if
-Cool Bizs
-
August 5th, 2002, 01:34 PM
#5
Thank you for your help. But according to what you said, listview with multi-selection enabled will always return 1 even no selection is made. But what I really want to do is to find out a specific selected item, and insert a new item after the selected one. If no list item is selected, my program appends the new item to the end of the existing list. The reason why I need to enable multi-selection is because my program will allow user to select a subset of consecutive items in the list and replace the entire subset with new items. As you said, .selectedItem always returns 1 even though there is no selection made. This will confuse my program coz my program will check if there is any selected item, if not, it will append a new item to the end, or else if an item is selected, it will add after it.
Thank you for your reply, and I am appreciated it!
-
August 5th, 2002, 02:00 PM
#6
Iterate through listitem object and check the .SELECTED property.
Code:
for nInd = 1 to ListView1.Listitems.Count
if (ListView1.ListItems(nInd).Selected) then
msgbox "Found the first selected item!"
exit for
end if
next nInd
-Cool Bizs
-
August 5th, 2002, 03:52 PM
#7
I have used a for loop to do that, but I just want to know if there is a more efficient way to do taht instead of using a for loop!
Thank you very much for your help!!
-
August 5th, 2002, 07:49 PM
#8
I don't know if this is what you are looking for but, here goes -
In the Item_Click event you can get the Index of the selected item. You could use a form wide variable to store the index each time you click on a item.
In the Item_Click event, to get the Index
(FormWideVariable) = Item.Index
You can then use the variable in other Subs, Functions, etc.
Hope this helped.
-
August 5th, 2002, 09:20 PM
#9
Originally posted by fongjeffrey
I have used a for loop to do that, but I just want to know if there is a more efficient way to do taht instead of using a for loop!
Thank you very much for your help!!
I don't know any other way to do this. It just does not seems possible to deselect the first item.
-Cool Bizs
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
|