VB编辑ListView的SubItem[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 jjkk168 的 blog

文件一,form1.frm

加入一个listview,两个imagelist,一个文本框

代码如下:
option explicit
'
' copyright ?1997-1999 brad martinez, http://www.mvps.org
'
' demonstrates how to in place do subitem editing in the vb listview.

private m_hwndlv as long   ' listview1.hwnd
private m_hwndtb as long   ' textbox1.hwnd
private m_iitem as long         ' listitem.index whose subitem is being edited
private m_isubitem as long   ' zero based index of listview1.listitems(m_iitem).subitem being edited
'

private sub form_load()
  dim i as long
  dim item as listitem
 
'  text1.appearance = ccflat   ' comctllib enum value
  text1.visible = false
  m_hwndtb = text1.hwnd
 
  ' initialize the imagelists
  with imagelist1
    .imageheight = 32
    .imagewidth = 32
    .listimages.add picture:=icon
  end with
 
  with imagelist2
    .imageheight = 16
    .imagewidth = 16
    .listimages.add picture:=icon
  end with
 
  ' initialize the listview
  with listview1
'    .labeledit = lvwmanual
    .hideselection = false
    .icons = imagelist1
    .smallicons = imagelist2
    m_hwndlv = .hwnd
   
    for i = 1 to 4
      .columnheaders.add text:="column" & i
    next
   
    for i = 0 to &h3f
      set item = .listitems.add(, , "item" & i, 1, 1)
      item.subitems(1) = i * 10
      item.subitems(2) = i * 100
      item.subitems(3) = i * 1000
    next
  end with
 
 
end sub

private sub form_resize()
'  listview1.move 0, 0, scalewidth, scaleheight
end sub

private sub listview1_dblclick()
  dim lvhti as lvhittestinfo
  dim rc as rect
  dim li as listitem
   
  ' if a left button double-click... (change to suit)
  if (getkeystate(vbkeylbutton) and &h8000) then
 
    ' if a listview subitem is double clicked...
    call getcursorpos(lvhti.pt)
    call screentoclient(m_hwndlv, lvhti.pt)
    if (listview_subitemhittest(m_hwndlv, lvhti) <> lvi_noitem) then
      if lvhti.isubitem then
       
        ' get the subitem's label (and icon) rect.
        if listview_getsubitemrect(m_hwndlv, lvhti.iitem, lvhti.isubitem, lvir_label, rc) then
         
          ' either set the listview as the textbox parent window in order to
          ' have the textbox move method use listview client coords, or just
          ' map the listview client coords to the textbox's paent form
  '        call setparent(m_hwndtb, m_hwndlv)
          call mapwindowpoints(m_hwndlv, hwnd, rc, 2)
          text1.move (rc.left + 4) * screen.twipsperpixelx, _
                              rc.top * screen.twipsperpixely, _
                              (rc.right - rc.left) * screen.twipsperpixelx, _
                              (rc.bottom - rc.top) * screen.twipsperpixely
         
          ' save the one-based index of the listitem and the zero-based index
          ' of the subitem(if the listview is sorted via the  api, then listitem.index
          ' will

本文关键:VB编辑ListView的SubItem
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top