Hello,
I have being trying to learn VB.net in my own time.
I am at this small project now for months and it is driving me up the walls.
Please bear with me.
In the project I have two ListBox's.
I want to click a button 'cmd1' and have the hightlight item name in one of the two ListBox's be passed to a MsgBox.
Hopefully I can explain it better though pseudocode:
The problem I am having is this:IF ListView1 Focused = True DO
VAR ListView1Selected = ListView1 Focused Item Selected
OUTPUT ListView1Selected
ELSEIF ListView2 Focused = True DO
VAR ListView2Selected = ListView2 Focused Item Selected
OUTPUT ListView2Selected
ELSE
OUTPUT "Notting"]
When I have a item selected in ListView2 and click the button, I get this error: "NullReferenceException was unhandled".
It doesn't matter if i swap the code around like below, I still get the same error.
IF ListView2 Focused = True DO
VAR ListView2Selected = ListView2 Focused Item Selected
OUTPUT ListView2Selected
ELSEIF ListView1 Focused = True DO
VAR ListView1Selected = ListView1 Focused Item Selected
OUTPUT ListView1Selected
ELSE
OUTPUT "Notting"]
Here is the full sub to look at. See what you can make of it:
Full Code Code:
Private Sub cmd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd1.Click If ListView2.FocusedItem.Selected = True Then Dim ListView2Selected As ListViewItem = ListView2.SelectedItems(0) MsgBox(ListView2Selected.ToString) ElseIf ListView1.FocusedItem.Selected = True Then Dim ListView1Selected As ListViewItem = ListView1.SelectedItems(0) [INDENT][/INDENT]Msgbox(ListView1Selected.ToString) Else MsgBox("notting selected") End If End Sub




Reply With Quote
