VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,456 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,629 people online right now. Registration is fast and FREE... Join Now!




ListView Small Probs

 

ListView Small Probs

ritu verma

3 Jul, 2009 - 10:11 AM
Post #1

New D.I.C Head
*

Joined: 10 Apr, 2009
Posts: 16

ListView Properties- I set MultiSelect to False, LabelEdit to true,FullRowSelect to True. I have Listview with two columns.

1) When I select onw row in listview,On button click i want to get the index of selected row. I m getting it but using for loop,I want to know is there a way to know the index of selected row,Without using the for loop.

CODE

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim lCount As Integer
        If ListView1.SelectedItems.Count > 0 Then
            For lCount = 0 To ListView1.Items.Count - 1
                If ListView1.Items(lCount).Selected Then
                    MsgBox(lCount.ToString)
                End If
                Application.DoEvents()
            Next
        End If
    End Sub


2) On Listview, double click,i want to edit the items of listview.

CODE

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim lCount As Integer
        Dim lvitem As ListViewItem

        For lCount = 1 To 3
            lvitem = ListView1.Items.Add(lCount)
            lvitem.SubItems.Add("ritu" & lCount)
            Application.DoEvents()
        Next
    End Sub

    Private Sub ListView1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
        ListView1.SelectedItems(0).BeginEdit()
    End Sub


When we double click on first row, 1 comes to edit mode, i want to know i want that second column text comes to edit mode..
So i write
CODE

ListView1.SelectedItems(1).BeginEdit()


But Error is there- InvalidArgument=Value of '1' is not valid for 'index'.
Parameter name: index

Can somebody tell me how to edit the second column text.

User is offlineProfile CardPM
+Quote Post


mark.bottomley

RE: ListView Small Probs

3 Jul, 2009 - 11:02 AM
Post #2

D.I.C Addict
****

Joined: 22 Apr, 2009
Posts: 780



Thanked: 127 times
My Contributions
ListView1.SelectedIndices.Item(0) will give you the index of the selected item. Protect it with a check for ListView1.SelectedIndices.Count > 0
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:03AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month