שתף באמצעות


ListView Selected Item Count....

Question

Tuesday, March 5, 2013 12:52 AM

First of all sory for my bad english :(

well i want to make a button to change text when i have select an item at Listview

i have make this but it doesnt works
it changes the name even i have select or not an item 

Private Sub Button1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.TextChanged
        If ListView1.SelectedItems.Count > 0 Then
            Button1.Text = "Edit"
        Else
            Button1.Text = "Add"
        End If
    End Sub

the default text of button is "Edit" 
If someone can help me i will be thankfull

 

All replies (6)

Tuesday, March 5, 2013 1:25 AM ✅Answered | 1 vote

Soublaki,

Try This code:

Public Class Form1    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged        If ListView1.SelectedItems.Count > 0 Then            Button1.Text = "Edit"        Else            Button1.Text = "Add"        End If    End Sub    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        ListView1.Items.Add("First")        ListView1.Items.Add("Second")    End SubEnd Class

Tuesday, March 5, 2013 12:58 AM | 1 vote

Insert a breakpoint at the line

    If ListView1.SelectedItems.Count > 0

Run the program.  When it stops at the breakpoint, what is the value of ListView1.SelectedItems.Count?  Continue the program with single stepping.  Which of the following statements is executed?

Are you quite sure that you are dealing with SelectedItems, and not CheckedItems?
Selected Items
http://msdn.microsoft.com/en-AU/library/system.windows.forms.listview.selecteditems.aspx
Checked Items
http://msdn.microsoft.com/en-AU/library/system.windows.forms.listview.checkeditems.aspx


Tuesday, March 5, 2013 1:20 AM

First thnks you for the reply...
Well i done what you say 
and it execute the 

Else
            Button1.Text = "Add"

yes i am sure...!


Tuesday, March 5, 2013 1:28 AM

What was the value of

  ListView1.SelectedItems.Count

when it stopped at that line?


Tuesday, March 5, 2013 1:32 AM

Thank you a lot my firend it works..!!
it hust needed to write the code at 

Private Sub ListView1_SelectedIndexChanged

Tuesday, March 5, 2013 1:34 AM

You are welcome.