CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Location
    pune
    Posts
    6

    Editing column of List view control

    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

  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Editing column of List view control

    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
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured