|
-
May 3rd, 2008, 04:24 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] List view selecteditem question
Dear all,
I added 3 item(day, month, year) into listview under a group, then I select one of the item, how do I get the selected item?
I have try this, but it is nothing happen:
Code:
If ListView1.SelectedItems.Equals("day") Then
TextBox1.Text = "Daily report"
End If
-
May 3rd, 2008, 04:34 AM
#2
Re: [2005] List view selecteditem question
Have you done any reading? I'll wager not. This is how you SHOULD have found the answer for yourself:
1. Go to the MSDN documentation index.
2. Lookup the ListView.SelectedItems property and get its type.
3. Go to the documentation for that type and read about it.
You would now know that its a ListView.SelectedListViewItemCollection object and, just like every other collection, it has an Item property that you can use to get an item from the collection.
4. Read the documentation for the Item property.
So, if there's only one selected item then you want the item at index 0. You would now know that that will return a ListViewItem object, which is the item selected in the ListView.
5. Read the documentation for the ListViewItem class.
You would now know that it has a Text property that returns the text of that item. Once you've got that text you can compare it to another String.
So, with just a few mouse clicks and a few minutes reading, all the information you needed has been obtained from the documentation that Microsoft provided free of charge with your IDE. They even made it easy to access from the Help menu.
-
May 3rd, 2008, 04:46 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] List view selecteditem question
I really read MSDN before asking this time, I find that it is likely using combobox-selecteditem. but in combobox.selecteditem = "Monthly", it is work! But ListView1.SelectedItems = "Monthly", it is syntax error.
Also there are two parameter ListView1.SelectedItems(i as integer) and ListView1.SelectedItems(s as string).But also, there are syntax too.
-
May 3rd, 2008, 05:04 AM
#4
Re: [2005] List view selecteditem question
The ComboBox.SelectedItem and ListView.SelectedItems properties are quite different. First of all, the items in a ComboBox and ListView are quite different. Secondly, as the names suggest, ComboBox.SelectedItem returns a single item while ListView.SelectedItems return multiple items, or at least a collection that can contain multiple items. The fact that they're quite different is fairly clear from the fact that ComboBox.SelectedItem is type Object and ListView.SelectedItems is type ListView.SelectedListViewItemCollection.
Further, yes there are two overloads for the Item property: one that takes an Integer and one that takes a String. They are described as:
Gets the item at the specified index within the collection.
and:
Gets an item with the specified key from the collection.
So, ask yourself what information you have. Do you have a key for the item? Do you have an index for the item? Of course you've got an index. If there's only one then it must be at index zero. So, to get the first selected item you get the Item at index 0 from the SelectedItems.
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
|