ListView

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

Hello

When I delete a row from the listView, as row whose "Item(0).Selected"
property is set to "true", the row is removed, but I get this "dotted" box
being displayed in the position where the row which was deleted. What do I
need to do to get rid of the "dotted" lines?

Thanks in advance for your assistance....
 
Hi Jim,
Normaly the listview is multiselectable (and otherwise you can use the same
methode).
Do you remove the selected items with?
\\\\
Dim lsv as Listviewitem
for each lsv in listview1.selecteditems
listview1.items.remove(lsv)
next
//////
Cor
 
Hello,

Jim Heavey said:
When I delete a row from the listView, as row
whose "Item(0).Selected" property is set to "true",
the row is removed, but I get this "dotted" box
being displayed in the position where the row which
was deleted. What do I need to do to get rid of the
"dotted" lines?

Which Windows version do you use?

Regards,
Herfried K. Wagner
 
Here is my answer to both Cor and Herfried questions.
Cor.
I am using a routine to determine the "real" index of the row selected, and
then once I have that index, I use the remove command with the index to do the
delete. I realize that I could do it in the manner which is described in your
note, but I need to know the real position of the item, so that I can adjust
the undelying table used to build the listview.

The actual code I am using is as follows:

Dim rowNbr As Integer = FindIndexOfSelectedItem(lsvCurrFileTypes)
lsvCurrFileTypes.Items(rowNbr).Remove()
If lsvCurrFileTypes.Items.Count > 0 Then
lsvCurrFileTypes.Items(0).Selected = True
End If

Private Function FindIndexOfSelectedItem(ByVal lsv As ListView) As Integer
Dim item As ListViewItem
Dim indx As Integer = 0
For Each item In lsv.Items
If item Is lsv.SelectedItems(0) Then
Return indx
End If
indx += 1
Next
Return -1
End Function

Herfried.
I am using Windows XP with Service pack 1 applied.
 
Hi Jim,
I made a few changes. I don't know if it has effect, but I don't know if the
for each loop follows the index or an internal order.
Maybe Herfried knows that and than he maybe can tell you.
I think this works, but if your strange lines are disappeared with that?
I doubt it, but you can always try.
\\\\\
Dim rowNbr As Integer = FindIndexOfSelectedItem(lsvCurrFileTypes)
If rowNBR > -1 then lsvCurrFileTypes.Items(rowNbr).Remove()
If lsvCurrFileTypes.Items.Count > 0 Then
lsvCurrFileTypes.Items(0).Selected = True
End If
Private Function FindIndexOfSelectedItem(ByVal lsv As ListView) As Integer
Dim indx As Integer = 0
For indx = 0 To lsv.Items.Count - 1
If lsv.Items(indx).Selected Then
Return indx
End If
Next
Return -1
End Function
////
Cor
 
Hi Cor

It seems that I provided the wrong version of the "FindIndexOfSelectedItem" as
your suggested coding changes are indicative of that. The one that I should
have provided does not use the "For Next" loop but a straight index as your
coding changes show. Sorry about that>

The "dotted" lines still remain, even with this code. The dotted lines appear
on the item which "replaces" the item which was deleted (the deleted item was
"selected"). It not a big deal, but it looks a bit strange. I can't explain
it.
 
Hi Jim,
I forgot to tell you, official you have to do before your start
listview.beginupdate and when it is ready listview.endupdate.
I readed that it is mainly for performance.
There is too a listview.update I did not use it, but when I understand it
right that does a redraw from the listview.
Maybe it helps when you start with
listview1.beginupdate()
................
listview1.endupdate()
listview1.update

When you forget a listview.endupdate than your listview freezes.
Cor
 
Cor...
Well, I finally got aroung to adding the suggested ".beginUpdate" and
".endUpdate", but it had not effect. The item which takes the place of the
item in the list which was deleted, appears "sunken" with dotted lines
surrounding it.

No impact on functionality, gut still goofy looking. I guess I will put this
in my mystery file.

Thanks for all your help...
 
Back
Top