Jump to content
Xtreme .Net Talk

Update selected Listview Subitem with Property Set by another Form


Recommended Posts

Posted

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:

 


   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:

 


   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:

   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:

   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.

  • Leaders
Posted
Which line are you getting the error on? Also, you should be able to hover the mouse over any identifier and a tooltip should pop up with the variable's or property's value.
[sIGPIC]e[/sIGPIC]
Posted

I get the error on this line:

 Me.ListView1.Items(lvwItem).SubItems(4).Text = Class1.Value1  

 

And I am able to mouse over each variable and see the values of each. They all contain the correct values.

Posted

Yeah, Class1 has a value. I think I know what I am going to do to fix it though. I am going to store all the values in ListView1 as local variables then remove the item before i do the update. After that I will just readd with new value. I think this will be the easiest way to get around my issue.

 

Sorry it took so long to respond. Was fighting other battles with the application.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...