DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Threaded View

  1. #1
    Join Date
    Jan 2006

    copy and paste in listview

    Hi everybody

    I have the following codes below on copy and paste routine within a listview and I would like to do a multiple rows of copy within the same listview and it has been achieved. However, i have a problem. I have attached a screen dump on this. The first listview shown is when the user right click and trying to copy the 3 rows starting from logical number 0 to 2 and paste to the rows starting from logical number 7. The screen dump shows that the rows of data is being copied but the logical number 7 onwards is overwrite by the logical number 0 to 2 which i don't want this to happen. This means when i do the multiple copy of rows of data, it copy the data starting with subitems(0). How do i modify the code to start with subitems(1).can anyone advice me ? thank u very much.

    Private Sub _listviewContextMenu_Copy(ByVal sender As Object, ByVal e As System.EventArgs)
            ' clicked somewhere odd:
            If ListView4.SelectedItems.Count > 0 Then
                ReDim copiedLVItems(ListView4.SelectedItems.Count - 1)
            End If
            Dim itemIndex As Int32
            For Each _listviewItemToCutOrCopy In ListView4.SelectedItems
                copiedLVItems(itemIndex) = _listviewItemToCutOrCopy.Clone
                itemIndex += 1
            _listviewAction = ListviewAction.Copying
        End Sub
    Private Sub _listviewContextMenu_Paste(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim i As Integer
            ' clicked somewhere odd:
            Select Case _listviewAction
                Case ListviewAction.Cutting
                    Dim toLvi As ListViewItem = ListView4.SelectedItems(0)
                    For i = 1 To toLvi.SubItems.Count - 1
                        ' this starts at the first subitem ?!
               toLvi.SubItems(i).Text = _listviewItemToCutOrCopy.SubItems(i).Text
                    ' may paste again, but don't cut again:
                    _listviewAction = ListviewAction.Copying
                Case ListviewAction.Copying
      ' this will overwrite an existing listview item, you might want to insert instead
                ' may paste again, but don't cut again:
                    'Alternate Paste Routine 
                    'Ensure items are available for pasting 
            If Not copiedLVItems Is Nothing AndAlso copiedLVItems.Length > 0 Then
                'Get currently selected index so we know where to start the paste 
                        Dim currentIndex As Int32 = 0
            If ListView4.SelectedIndices.Count > 0 Then currentIndex = ListView4.SelectedIndices.Item(ListView4.SelectedIndices.Count - 1)
                        Dim li As ListViewItem
                            For Each li In copiedLVItems
                                ListView4.Items.Insert(currentIndex, li)
                                currentIndex += 1
                            MsgBox(Err.Description) '<- will tell you the error
                            Dim removeLI As ListViewItem
                            'Remove all selected items 
                            For Each removeLI In ListView4.SelectedItems
                        End Try
                    End If
            End Select
        End Sub
    Attached Images Attached Images

Similar Threads

  1. VB.NET Question Copy and Paste
    By Raffee in forum .NET
    Replies: 12
    Last Post: 04-07-2009, 11:33 PM
  2. copy paste fails on second use, CSV
    By dmb-job in forum VB Classic
    Replies: 0
    Last Post: 06-30-2005, 06:11 PM
  3. Excel Copy & Paste
    By Portree in forum VB Classic
    Replies: 7
    Last Post: 03-22-2005, 06:53 PM
  4. Copy paste images from Clipboard
    By Chetan in forum Java
    Replies: 0
    Last Post: 09-28-2001, 03:58 AM
  5. Copy and Paste
    By Bob in forum VB Classic
    Replies: 1
    Last Post: 05-04-2001, 08:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.