943,789 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 949
  • VB.NET RSS
Jul 3rd, 2009
0

ListView Small Probs

Expand Post »
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.

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim lCount As Integer
  3. If ListView1.SelectedItems.Count > 0 Then
  4. For lCount = 0 To ListView1.Items.Count - 1
  5. If ListView1.Items(lCount).Selected Then
  6. MsgBox(lCount.ToString)
  7. End If
  8. Application.DoEvents()
  9. Next
  10. End If
  11. End Sub

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

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. Dim lCount As Integer
  3. Dim lvitem As ListViewItem
  4.  
  5. For lCount = 1 To 3
  6. lvitem = ListView1.Items.Add(lCount)
  7. lvitem.SubItems.Add("ritu" & lCount)
  8. Application.DoEvents()
  9. Next
  10. End Sub
  11.  
  12. Private Sub ListView1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
  13. ListView1.SelectedItems(0).BeginEdit()
  14. 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
VB.NET Syntax (Toggle Plain Text)
  1. 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.
Similar Threads
Reputation Points: 16
Solved Threads: 1
Light Poster
ritu verma is offline Offline
33 posts
since Apr 2009
Jul 3rd, 2009
0

Re: ListView Small Probs

ListView1.SelectedItems(1).BeginEdit() cant worrk out. You have multiselect set to false so there is always only one item selected. so it have to stick on 0.
remember ListView1.SelectedItems(1) doesnt mean its the next item in list, its the next selected item (which doesnt exist on multiselect=False)
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Jul 5th, 2009
0

Re: ListView Small Probs

1) since multiselect is false
listview1.selecteditems(1) is not possible
it has to be listview1.selecteditem(0)
since u want a particular column add another parameter.
listview1.selecteditem(0)(1)
this should fetch the second row.
this is just like a 2 dimensional array or a matrix.
first parameter is the row and the second parameter is the column
Reputation Points: -1
Solved Threads: 23
Posting Whiz in Training
babbu is offline Offline
207 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: syntax error in INSERT INTO statement
Next Thread in VB.NET Forum Timeline: loginid and password form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC