Replace item in last row, column 10 in listview

DiverDan

Contributor
Joined
Jan 16, 2003
Messages
645
Location
Sacramento, CA
I have noticed that Listview does not have a replace option, so...
How can one replace a value in the last row, 10th column in a listview with a new value?

Thanks
 
Visual Basic:
Dim itmX As ListViewItem
' Get the last item into itmX
itmX = ListView1.Items(ListView1.Items.Count - 1)
' Change column 10s text
itmX.SubItems(9).Text = "My replaced text"
' Put back into listview as last item
ListView1.Items(ListView1.Items.Count - 1) = itmX

Hope this helps

Andy
 
Thanks Andy,

Your code works fantastic!!!

I did notice that it did produce some screen flicker though.
Is there a way to postpone the screen refresh until the listview line is replaced? (or maybe its my old Video card)

Thanks
 
Last edited:
No its not flicker you can make it so no screen flick doesn't happen by the following code....

Visual Basic:
        Dim itmX As ListViewItem
        ListView1.BeginUpdate()
        itmX = ListView1.Items(ListView1.Items.Count - 1)
        itmX.SubItems(9).Text = "BLUE"
        ListView1.Items(ListView1.Items.Count - 1) = itmX
        ListView1.EndUpdate()

give that a go

Andy
 
If it is possible, I have one more listview question.

I'd like to save the listview contents into a serialized array each time it is updated. Then, if needed through the mnuUndo, pop it back into the listview by deserializing the array with your update method...
 
Back
Top