Ok, I am trying to update the value of SubItem(4) of the selected listview item using a property which is set by another form.
Here are the forms I have:
FormA (Form with ListView1)
FormB (Form with TextBox1 that sets Class1.Value1)
What I do is populate ListView1 based on other selections the user makes on FormA. If they want to change the value for SubItem(4) they click a button which launches FormB.
FormA Sets a property to the ListView1 Selected Index with the following code:
FormA then does the following when clicking the "Edit" button:
FormB has the following Code:
FormA is trying to us the UpdateValue1 sub which looks like this:
When I get to the UpdateValue1 all the correct values are set for the Properties but I keep getting the following error: "Object reference not set to an instance of an object."
Now, I do not close FormA when launching FormB so I am confused as to why its stating I need to reference an Instance of an Object. To be totally honest, I am still really new with the whole programming thing. I have written some VBA (please dont laugh) for Excel. This is my first full VS2005 project.
Any help would be greatly appreciated.
Here are the forms I have:
FormA (Form with ListView1)
FormB (Form with TextBox1 that sets Class1.Value1)
What I do is populate ListView1 based on other selections the user makes on FormA. If they want to change the value for SubItem(4) they click a button which launches FormB.
FormA Sets a property to the ListView1 Selected Index with the following code:
Code:
Private Sub ListView1 _SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Dim lstrSelected As String
If ListView1.SelectedItems.Count > 0 Then
cmdEdit.Enabled = True
cmdRemove.Enabled = True
Dim selNdx = Me.ListView1.SelectedIndices(0)
If selNdx >= 0 Then
lstrSelected = ListView1.Items(selNdx).Text
Class1.Selected = lstrSelected
End If
End If
End Sub
FormA then does the following when clicking the "Edit" button:
Code:
Private Sub cmdEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdEdit.Click
Class1.Value1= CInt(ListView1.SelectedItems(0).SubItems(4).Text)
FormB.Show()
End Sub
FormB has the following Code:
Code:
Private Sub cmdOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Class1.Value1 = Me.TextBox1 .Text
Close()
FormA.UpdateValue1()
End Sub
FormA is trying to us the UpdateValue1 sub which looks like this:
Code:
Public Sub UpdateValue1()
Dim lvwItem As String
lvwItem = Class1.Selected
Me.ListView1.Items(lvwItem).SubItems(4).Text = Class1.Value1
End Sub
When I get to the UpdateValue1 all the correct values are set for the Properties but I keep getting the following error: "Object reference not set to an instance of an object."
Now, I do not close FormA when launching FormB so I am confused as to why its stating I need to reference an Instance of an Object. To be totally honest, I am still really new with the whole programming thing. I have written some VBA (please dont laugh) for Excel. This is my first full VS2005 project.
Any help would be greatly appreciated.