Question ListView Selected Item Count....

soublaki

New member
Joined
Mar 4, 2013
Messages
2
Programming Experience
Beginner
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


VB.NET:
[COLOR=#000088]Private[/COLOR][COLOR=#000088]Sub[/COLOR][COLOR=#000000] Button1_TextChanged[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]ByVal[/COLOR][COLOR=#000000] sender [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000088]Object[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000088]ByVal[/COLOR][COLOR=#000000] e [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]EventArgs[/COLOR][COLOR=#666600])[/COLOR][COLOR=#000088]Handles[/COLOR][COLOR=#000000] Button1[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]TextChanged[/COLOR]
[COLOR=#000088]If[/COLOR][COLOR=#000000] ListView1[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]SelectedItems[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Count [/COLOR][COLOR=#666600]>[/COLOR][COLOR=#006666]0[/COLOR][COLOR=#000088]Then[/COLOR][COLOR=#000000]           
Button1[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Text [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#008800]"Edit"
[/COLOR][COLOR=#000088]Else[/COLOR][COLOR=#000000]          
Button1[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Text [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#008800]"Add"
[/COLOR][COLOR=#000088]End[/COLOR][COLOR=#000088]If 
[/COLOR][COLOR=#000088]End[/COLOR][COLOR=#000088]Sub[/COLOR]

If someone can help me i will be thankfull
 
It's no use handling the TextChanged event of the Button because it is raised when the Text of the Button changes. If you haven't changed the Text of the Button then the event will never be raised. If you want to do something when the user changes the selection in the ListView then you need to handle the event that's raised when the selection changes in the ListView. Consult the MSDN documentation for the ListView class to find out what events it has and then you can determine which one you need to handle.
 
I find it the solution is these :


VB.NET:
[COLOR=#660066]Private [/COLOR][COLOR=#660066]Sub [/COLOR][U][B][COLOR=#660066]ListView1_SelectedIndexChanged[/COLOR][/B][/U][COLOR=#666600]([/COLOR][COLOR=#660066]ByVal[/COLOR][COLOR=#000000] sender [/COLOR][COLOR=#660066]As[/COLOR][COLOR=#660066]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Object[/COLOR][COLOR=#666600],[/COLOR][COLOR=#660066]ByVal[/COLOR][COLOR=#000000] e [/COLOR][COLOR=#660066]As[/COLOR][COLOR=#660066]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]EventArgs[/COLOR][COLOR=#666600])[/COLOR][COLOR=#660066]Handles [/COLOR][COLOR=#660066]ListView1[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]SelectedIndexChanged[/COLOR]
[COLOR=#660066]If [/COLOR][COLOR=#660066]ListView1[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]SelectedItems[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Count [/COLOR][COLOR=#666600]> [/COLOR][COLOR=#006666]0 [/COLOR][COLOR=#660066]Then
[/COLOR][COLOR=#660066]Button1[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Text[/COLOR][COLOR=#666600]=[/COLOR][COLOR=#008800]"Edit"
[/COLOR][COLOR=#660066]Else
[/COLOR][COLOR=#660066]Button1[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Text[/COLOR][COLOR=#666600]=[/COLOR][COLOR=#008800]"Add"
[/COLOR][COLOR=#660066]End[/COLOR][COLOR=#660066]If 
[/COLOR][COLOR=#660066]End[/COLOR][COLOR=#660066]Sub[/COLOR]
 
Back
Top