?
Solved

[VB6.0/SP5] how can i remove a row of ListView?

Posted on 2003-03-26
7
Medium Priority
?
362 Views
Last Modified: 2012-06-21
hi,
    I fill listview some rows, then i will add/remove some rows of the listview. after i remove one/multi rows of listview, i'd like the following rows rose. for example:

     +-----+-----+-----+------+
     | col1|col2 |col3 | col4 |
     +-----+-----+-----+------+
     | 1   |a    |b    | c    |
     | 2   |d    |e    | f    |
     | 3   |g    |h    | i    |
     | 4   |l    |b    | c    |
     +-----+-----+-----+------+
   
    after i remove the 2nd row, the listview should be :
     +-----+-----+-----+------+
     | col1|col2 |col3 | col4 |
     +-----+-----+-----+------+
     | 1   |a    |b    | c    |
     | 3   |g    |h    | i    |
     | 4   |l    |b    | c    |
     +-----+-----+-----+------+

     how can i do?

     Best Regards.

    --lr  
0
Comment
Question by:LuRen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 1

Author Comment

by:LuRen
ID: 8209023
Sorry for the format of the list. it looks good in notepad. :)
     -- lr
0
 

Expert Comment

by:gepi
ID: 8209066
You can remove a row from a listview, by calling the Remove method of ListItems property.
Ex:
ListView1.ListItems.Remove 2
0
 
LVL 1

Author Comment

by:LuRen
ID: 8209145
gepi,
   how can i get the number of the row? i'd like remove the selected row.
   
   Regards,
 
   -- lr
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
DocM earned 80 total points
ID: 8209172

ListView1.ListItems.Remove ListView1.SelectedItem.Key
0
 
LVL 1

Author Comment

by:LuRen
ID: 8214943
DocM,
    You answer give me a tip. the statement should be:
   
    ListView1.ListItems.Remove ListView1.SelectedItem.Index

   BTW, you should get the points.
   
   Thanks.

  -- lr
0
 

Expert Comment

by:gepi
ID: 8215922
LuRen, your sollution is not so good, because, if you don't set the Key of an item, your sollution will crash.
This is the corect implementation.
----------------------------------------------
'Put this method in your form.
Private sub RemoveSelected(objList as ListView)
  Dim objListItem as ListItem
  set objListItem=objList.SelectedItem
  If Not objListItem is nothing then
   objList.ListItems.Remove objListItem.Index
  Endif
End Sub
-----------------------------------
How to call it:

RemoveSelected ListView1
-----------------------------
You can put the RemoveSelected procedure in a module by Public. So, you will be able to call it from any form you want.

Best Regards Gepi
0
 
LVL 1

Author Comment

by:LuRen
ID: 8222041
gepi,

    thank you. you are right.

      --lr
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question