?
Solved

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

Posted on 2003-03-26
7
Medium Priority
?
364 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
  • 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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

621 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