1 Replies - 539 Views - Last Post: 28 December 2017 - 11:12 AM Rate Topic: -----

#1 shiftadelete   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 04-November 16

How to change/update selected listview item from another form vb.net

Posted 28 December 2017 - 10:24 AM

I was doing removing items from another form for listbox and it was working good.

Now I want to do with listview but I couldn't do it here is my listbox codes.. And I am using classes

Dim WithEvents myedit As New Form2
Dim WithEvents mynew As New Form2

Private Sub btnModify_Click(sender As Object, e As EventArgs)
    If ListBox1.SelectedIndex <> -1 Then
        Dim std As New studentinf
        std = studentinf.studentinformation(ListBox1.SelectedIndex)
        myedit.txtnumber.Text = std.number
        myedit.txtname.Text = std.namesurname
        myedit.txtquiz.Text = std.quiz
        myedit.txtmidterm.Text = std.midterm
        myedit.txtfinal.Text = std.final
        myedit.ShowDialog()
    Else
        MsgBox("Select to modify")
    End If
End Sub

Sub DoModify() Handles myedit.Done
    Dim std As studentinf

    std = studentinf.studentinformation(ListBox1.SelectedIndex)
    std.number = myedit.txtnumber.Text
    std.namesurname = myedit.txtname.Text
    std.quiz = myedit.txtquiz.Text
    std.midterm = myedit.txtmidterm.Text
    std.final = myedit.txtfinal.Text

    ListBox1.Items(ListBox1.SelectedIndex) = std.number & vbTab & vbTab & std.namesurname & vbTab & vbTab &
       std.quiz & vbTab & vbTab & std.midterm & vbTab & vbTab & std.final
End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: How to change/update selected listview item from another form vb.net

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5239
  • View blog
  • Posts: 14,035
  • Joined: 18-April 07

Re: How to change/update selected listview item from another form vb.net

Posted 28 December 2017 - 11:12 AM

So listview uses an items collection to add items to it. So first you create the listviewitem, then add some values to it using its "subitems" collection. Think of it is as building up an item and then adding the item to the listview using that items collection. This page has a great little example to show you how to do it.

https://msdn.microso...#code-snippet-2

Pay particular attention to the lines about 20 lines down where it starts with item1, item2 and item3. It sets up each of those items and then creates some columns to match the items. The magic comes in right after this where it adds the items to the listview.Items collection using the "AddRange" method. But you don't have to use that, and you can add each item after you are done setting it up just by using listview.Items.Add().

As you can see it is a little more work but offers you some greater flexibility. Hope this helps you out. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1