ListView Small Probs

Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Apr 2009
Posts: 33
Reputation: ritu verma is an unknown quantity at this point 
Solved Threads: 1
ritu verma ritu verma is offline Offline
Light Poster

ListView Small Probs

 
0
  #1
Jul 3rd, 2009
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.

  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.

  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
  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 225
Reputation: GeekByChoiCe is on a distinguished road 
Solved Threads: 39
GeekByChoiCe GeekByChoiCe is offline Offline
Posting Whiz in Training

Re: ListView Small Probs

 
0
  #2
Jul 3rd, 2009
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)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 132
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 13
babbu babbu is offline Offline
Junior Poster

Re: ListView Small Probs

 
0
  #3
Jul 5th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC