1.11M Members

how to refresh listview in vb.net

 
0
 

Hello, I have a listview wherein when I double click a student another form pops up where i edit the student info. When i click on cancel it goes back to the menu and when i click on the reports i want it to be able to refresh so that i wont have to close the program again. Thank you for your help.

Much appreciated! :D

 
0
 

You double click on an entry (a student) in a listview. This brings up an edit form. If you click on cancel (which is what you stated), typically the response is to discard the changes in the edit form so hitting refresh would be pointless as there are no changes.

When you say you go back to the menu do you mean the form that you were in when you double clicked on the student? What do you mean by "when I click on the reports"? And what do you want to refresh? We can't see your form(s) or your code so you'll have to be more specific.

 
0
 

I meant that when i clicked on cancel i finished editing and i want the listview to view the changes that i made on the edit form. But i what i have to do is to close the program and view the class list again to make sure that it is really edited.

 
0
 

.see If this helps.

Public Class Form1

    Private Sub ListView1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        With ListView1
            If Not .SelectedItems.Count = 0 Then
                With .SelectedItems(0) '// first selected.item.
                    Form2.TextBox1.Text = .Text
                    Form2.TextBox2.Text = .SubItems(1).Text
                    Form2.ShowDialog()
                End With
            End If
        End With
    End Sub
End Class
Public Class Form2

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        With Form1.ListView1
            If Not .SelectedItems.Count = 0 Then
                With .SelectedItems(0) '// first selected.item.
                    .Text = TextBox1.Text
                    .SubItems(1).Text = TextBox2.Text
                    Me.Close()
                End With
            End If
        End With
    End Sub
End Class
 
1
 

"Cancel" is universally regarded as "throw out what I did". Have a look at codeorder's code above. He's doing substance so I might as well do style. I suggest you relabel your button to something like "OK" or "COMMIT" instead of "Cancel" or you are going to confuse a lot of users.

OK - I'm happy with my changes. Please save them and continue
CANCEL - throw away my changes and continue

 
0
 

The cancel button is for exit. like, the listview have the records right, when the user double clicks the student in the listview, a new form will show, having the buttons, EDIT STUDENT and CANCEL so the cancel is just for the exit or like going back to menu, thinking about it, i think i should just change it CANCEL to BACK TO MENU.

Anyway, i'll try the code.

 
0
 

>>Anyway, i'll try the code.
If you're gonna try someone, don't try .Me cause I'll knock more than teeth out of a pillow. :D
.sorry, morning here, no coffee yet.:(
"code".order

 
0
 

What is this code for, what is the Form2 is that the list of class or the edit students information form?

Form2.TextBox1.Text = .Text
Form2.TextBox2.Text = .SubItems(1).Text

 
0
 

>>I have a listview wherein when I double click a student another form pops up where i edit the student info.
ListView for all.Students on Form1, TextBoxes for .Edit .SelectedStudent.Info on Form2.

 
0
 

Oh okay, i'll try it now

 
-1
 

shoot, the form for the list of class is not opening, there's no error it's just not opening, it's taking too long

 
0
 

Then, AndAlso, read your rep.comment.
Hope it helps to get you a solution quicker, and not waste the world's time w/nonsense.
Nothing personal, might help others in the future as well.:)

 
0
 

i don't know what happened but when i tried the code, whenever i click on the class list on the menu bar it's not opening. :/

 
0
 

.hmm.
If you can, attach the project in a .zip file.

 
0
 

somehow, when i tried the code the Class List Form is not showing anymore :/

 
0
 

>>Anyway, i'll try the code.
If you're gonna try someone, don't try .Me cause I'll knock more than teeth out of a pillow. :D
.sorry, morning here, no coffee yet.:(
"code".order

Lol :P ;)

 
0
 

how to refresh list view in vb.net after adding or updating data in data base

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: