|
-
Jun 21st, 2004, 10:29 AM
#1
Thread Starter
Addicted Member
ListView [RESOLVED]
I have a listview box with 10 items in it. How do I create a statement saying if you select no items then show message, if you select items then message show, the items that were selected. Thanks! I know the command for show message, but can't figure out the if parts.
For emaple:
If lstParts.SelectedItems = None selected then display an Error Message
If lstParts.SelectedItems are selected then display a Message with those selected items.
Last edited by twisted; Jun 23rd, 2004 at 09:41 AM.
Twisted
-
Jun 21st, 2004, 10:56 AM
#2
Hyperactive Member
simple,
VB Code:
Dim sbMessage As System.Text.StringBuilder
Dim liTemp As ListViewItem
If lstParts.SelectedItems.Count > 0 Then
sbMessage.Append("You chose the following items").Append(vbCrLf)
For Each liTemp In lstParts.Items
If liTemp.Selected = True Then sbMessage.Append(liTemp.Text).Append(vbCrLf)
Next
MessageBox.Show(sbMessage.ToString)
Else
MessageBox.Show("Show some other message")
End If
Hope this helps
Last edited by CyberHawke; Jun 21st, 2004 at 11:03 AM.
-
Jun 21st, 2004, 10:59 AM
#3
Hyperactive Member
You can test the condition in this way:
Code:
If Me.LswScadenze.SelectedItems.Count > 0 Then
else
End If
If Count > 0 at least one item is selected.
This solve your problem?
Good job
Live long and prosper (Mr. Spock)
-
Jun 21st, 2004, 11:02 AM
#4
Thread Starter
Addicted Member
First part works great! But how do I get the second message (when items are selected) to show the items that have been selected. Say my items are arm, leg, and hand. And when I select arm and hand I want the message to say You have selected arm and hand.
-
Jun 21st, 2004, 11:04 AM
#5
Hyperactive Member
I updated my original message, check it out
-
Jun 21st, 2004, 11:10 AM
#6
Thread Starter
Addicted Member
Originally posted by CyberHawke
simple,
VB Code:
Dim sbMessage As System.Text.StringBuilder
Dim liTemp As ListViewItem
If lstParts.SelectedItems.Count > 0 Then
sbMessage.Append("You chose the following items").Append(vbCrLf)
For Each liTemp In lstParts.Items
If liTemp.Selected = True Then sbMessage.Append(liTemp.Text).Append(vbCrLf)
Next
MessageBox.Show(sbMessage.ToString)
Else
MessageBox.Show("Show some other message")
End If
Hope this helps
Didn't work out right! The first part did, but when I select items I end up with an error.
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe
Additional information: Object reference not set to an instance of an object.
-
Jun 21st, 2004, 11:21 AM
#7
Thread Starter
Addicted Member
-
Jun 21st, 2004, 12:27 PM
#8
Thread Starter
Addicted Member
Ok this is what I got so far, but need the items in my ListView that are selected to be displayed in my text box. Here's my code..
VB Code:
If lstParts.SelectedItems.Count = 0 Then
MessageBox.Show("You did not select any items", "Error")
Exit Sub
End If
If lstParts.SelectedItems.Count > 0 Then
txtLoop.Text = "You have selected: [COLOR=RED]THE ITEMS THAT WERE SELECTED[/COLOR]."
End If
-
Jun 21st, 2004, 02:08 PM
#9
Hyperactive Member
Sorry, I left out a key word in one of the declarations
The word new is required when declaring an instance of the stringbuilder class, or any other for that matter...
VB Code:
Dim sbMessage As New System.Text.StringBuilder
Dim liTemp As ListViewItem
If lstParts.SelectedItems.Count > 0 Then
sbMessage.Append("You chose the following items").Append(vbCrLf)
For Each liTemp In lstParts.Items
If liTemp.Selected = True Then sbMessage.Append(liTemp.Text).Append(vbCrLf)
Next
MessageBox.Show(sbMessage.ToString)
Else
MessageBox.Show("Show some other message")
End If
-
Jun 22nd, 2004, 06:29 AM
#10
Thread Starter
Addicted Member
Originally posted by CyberHawke
Sorry, I left out a key word in one of the declarations
The word new is required when declaring an instance of the stringbuilder class, or any other for that matter...
VB Code:
Dim sbMessage As New System.Text.StringBuilder
Dim liTemp As ListViewItem
If lstParts.SelectedItems.Count > 0 Then
sbMessage.Append("You chose the following items").Append(vbCrLf)
For Each liTemp In lstParts.Items
If liTemp.Selected = True Then sbMessage.Append(liTemp.Text).Append(vbCrLf)
Next
MessageBox.Show(sbMessage.ToString)
Else
MessageBox.Show("Show some other message")
End If
Now it works perfect! The only problem I have is I want to keep the "Show some other message", but not the "You chose the following items". Instead of a Message Box for this one I want it to show up in a text box. Saying "You have selected: arm, hand, and foot." If that's what they select. Would I just change the one line:
MessageBox.Show(sbMessage.ToString)??
EDIT: I went ahead and put txtLoop.Text = (sbMessage.ToString)
Now that it works I don't think I can use it. I believe I have to return these values using Do While, Do Until, and For Next statements.
It works great! One other question is DOES THIS use a text box for the loop results, and if so, how did they make it that size, b/c mine won't let me change the height??
Last edited by twisted; Jun 22nd, 2004 at 06:59 AM.
Twisted
-
Jun 22nd, 2004, 07:29 AM
#11
Thread Starter
Addicted Member
Another problem I found:
If I select any parts then my Message works, but after I select parts then go back and don't select parts my Message doesn't come up. It's like it is storing the times Parts have been selected and after the first time it's greater then 0 so it doesn't work.
-
Jun 22nd, 2004, 09:39 AM
#12
Hyperactive Member
one word here "CODE" as in I need to see some...
If you are attempting to not have any items in the list selected then I suggest you try clearing the selecteditems collection.
VB Code:
lstParts.SelectedItems.Clear
-
Jun 22nd, 2004, 09:46 AM
#13
Thread Starter
Addicted Member
VB Code:
Private Sub btnWhile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWhile.Click
Dim sbMessage As New System.Text.StringBuilder
Dim liTemp As ListViewItem
If lstParts.SelectedItems.Count > 0 Then
sbMessage.Append("This is a Do While loop and you chose the following items:").Append(vbCrLf)
For Each liTemp In lstParts.Items
If liTemp.Selected = True Then sbMessage.Append(liTemp.Text).Append(vbCrLf)
Next
txtLoop.Text = (sbMessage.ToString)
Else
MessageBox.Show("You did not select any items", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
End Sub
Right now, how do I make this a Do...While statement while mainting the same stuff? Also, how do I get my text box for the Loop Results to look like this? Is that even a text box??
-
Jun 22nd, 2004, 10:44 AM
#14
Hyperactive Member
yeah, it's a TextBox inside a GroupBox with the enabled property set to false and the backcolor property set to Control
-
Jun 22nd, 2004, 12:15 PM
#15
Thread Starter
Addicted Member
Well I got the GroupBox and Textbox inside it but I can change the height of the Textbox it's just default right now, but the width is perfect and let me adjust it fine.
-
Jun 22nd, 2004, 12:58 PM
#16
Hyperactive Member
Set the multiline property to true
-
Jun 22nd, 2004, 02:19 PM
#17
Thread Starter
Addicted Member
Last edited by twisted; Jun 23rd, 2004 at 09:41 AM.
Twisted
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
|