Click to See Complete Forum and Search --> : Editing column of List view control


Charu
May 23rd, 2001, 10:52 PM
I have three columns in my listview control. I want to edit third column of it. I could edit the first column using 'labeledit' property, but it is not allowing me to edit second and third column.

charusheela

Johnny101
May 24th, 2001, 09:09 AM
you have to cheat and place a text box over the corresponding column/row. here's the code:

option Explicit
Dim miItemIndex as Integer
Dim miColIndex as Integer

private Sub Text1_LostFocus()
If miColIndex = 1 then
ListView1.ListItems(miItemIndex).Text = Text1.Text
else
ListView1.ListItems(miItemIndex).SubItems(miColIndex - 1) = Text1.Text
End If
Text1.Visible = false
End Sub

private Sub Form_Load()
Dim itm as ListItem

set itm = ListView1.ListItems.Add(, , "John")
itm.SubItems(1) = "Smith"
itm.SubItems(2) = "123 ABC Street"

set itm = ListView1.ListItems.Add(, , "Karen")
itm.SubItems(1) = "Jones"
itm.SubItems(2) = "456 DEF St."

End Sub

Sub EditListView(iCol as Integer)
With Text1
.Left = ListView1.Left + ListView1.ColumnHeaders(iCol).Left + 15
.Top = ListView1.Top + ListView1.SelectedItem.Top
.Visible = true
.SetFocus
End With
miItemIndex = ListView1.SelectedItem.Index
End Sub

private Sub ListView1_MouseUp(Button as Integer, Shift as Integer, x as Single, y as Single)
Dim i as Integer

If Button = vbLeftButton then
If Not ListView1.SelectedItem is nothing then
for i = 1 to ListView1.ColumnHeaders.Count
If x < ListView1.Left + ListView1.ColumnHeaders(i).Left + ListView1.ColumnHeaders(i).Width _
And x > ListView1.Left + ListView1.ColumnHeaders(i).Left then
Call EditListView(i)
miColIndex = i
End If
next i
End If
End If

End Sub




this might need some tweaking, but it should get you well on your way.

hope this helps,

john

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org