Results 1 to 3 of 3

Thread: MULTISELECT listview items...

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,943

    MULTISELECT listview items...

    I have a listview filled with value.
    Is possible to select one or more line in listy view and store the value of first item in a sheet.
    Example:

    in listview
    column1 column2 column3
    10000 aaaaaaaa bbbbbbbb
    15000 zzzzzzzzz cccccccc
    ...
    20000 hhhhhhhh adababab

    i select line 1 and line 2
    the lines seected assuming autoamticlly the black color

    insert in sheet:
    column a column b column c
    10000 aaaaaaaa bbbbbbbb
    15000 zzzzzzzzz cccccccc

    naturally if i reclick on line 1 and 2 in listview delete the refered line in sheet and recolr the line in listview with the color of deault...


    Sorry for bad english but i hope understand me:-)

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MULTISELECT listview items...

    Not sure if I understand you but

    Select 2 rows in a listview.
    Copy to Excel
    Paste

    Where is this listview at?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: MULTISELECT listview items...

    I am assuming that you are using Excel 2003...

    Here is a sample code to export data from listview to excel sheet....

    vb Code:
    1. '~~> Generating Sample Data.
    2. Private Sub UserForm_Activate()
    3.     '~~> Ensure that the listview's multiselect property is set to true
    4.     Dim clmAdd As ColumnHeader, itmAdd As ListItem, j As Integer
    5.  
    6.     '~~> Adding 3 Column Headers to the ListView control
    7.     Set clmAdd = ListView1.ColumnHeaders.Add(Text:="Header1")
    8.     Set clmAdd = ListView1.ColumnHeaders.Add(Text:="Header2")
    9.     Set clmAdd = ListView1.ColumnHeaders.Add(Text:="Header3")
    10.  
    11.     '~~> Set the view property of the Listview control to Report view
    12.     ListView1.View = lvwReport
    13.  
    14.     '~~> Adding Sample data to the ListView control
    15.     For j = 1 To 5
    16.         Set itmAdd = ListView1.ListItems.Add(Text:="Sample " & j)
    17.         itmAdd.SubItems(1) = "SampleSubItemOne" & j
    18.         itmAdd.SubItems(2) = "SampleSubItemTwo" & j
    19.     Next j
    20. End Sub
    21.  
    22. '~~> Export Data to Sheet from listview
    23. Private Sub CommandButton1_Click()
    24.     Dim i As Integer, R As Integer
    25.    
    26.     '~~> Get the First Empty Row
    27.     R = Sheets("Sheet1").Range("A65536").End(xlUp).Row + 1
    28.    
    29.     For i = 1 To ListView1.ListItems.Count
    30.         If ListView1.ListItems(i).Selected = True Then
    31.             '~~> Data copied to Column A, B and C
    32.             Sheets("Sheet1").Range("A" & R).Value = ListView1.ListItems(i).Text
    33.             Sheets("Sheet1").Range("B" & R).Value = ListView1.ListItems(i).SubItems(1)
    34.             Sheets("Sheet1").Range("C" & R).Value = ListView1.ListItems(i).SubItems(2)
    35.             R = R + 1
    36.         End If
    37.     Next i
    38. End Sub

    I am sure you can take care of

    naturally if i reclick on line 1 and 2 in listview delete the refered line in sheet and recolr the line in listview with the color of deault...
    If you get stuck, simply post the code that you have tried and we will definitely help you out
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width