Ok, so i have been following along with the examples.... When i enter this:
Code:
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
'If no customer is selected in the ListBox then...
If lstCustomers.SelectedIndex = -1 Then
'Display a message
MessageBox.Show("You must select a customer to delete.", "Structure Demo")
Exit Sub
End If
If MessageBox.Show("Are you sure you want to delete " & SelectedCustomer.Name & "?", "Structure Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'Get the customer object to be deleted
Dim objCustomerToDelete As Customer = SelectedCustomer
'Remove the customer from the array list
objCustomers.Remove(objCustomerToDelete)
'Remove the customer from the listBox
lstCustomers.Items.Remove(objCustomerToDelete)
End If
End Sub
Public ReadOnly Property SelectedCustomer() As String
Get
If lstCustomers.SelectedIndex <> -1 Then
Return lstCustomers.Items(lstCustomers.SelectedIndex)
End If
End Get
End Property
I get 2 errors and 1 warning.
The errors are:
'Name' is not a member of 'String'
which points to this line:
Code:
If MessageBox.Show("Are you sure you want to delete " & SelectedCustomer.Name & "?", "Structure Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Value of type 'String' cannot be converted to 'StructureDemo.Customer'
Which doesn't like this line
Code:
Dim objCustomerToDelete As Customer = SelectedCustomer
The warning is:
Property 'SelectedCustomer' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
any thoughts?