当用API改变listview的列头为扁平后,他就不能响应ColumnClick事件了,有没有解决办法?

laviewpbt laviewpbt 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ?1996-2005 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const HDS_BUTTONS As Long = &H2
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETHEADER As Long = (LVM_FIRST + 31)
Private Const GWL_STYLE As Long = (-16)
Private Const SWP_DRAWFRAME As Long = &H20
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOZORDER As Long = &H4
Private Const SWP_FLAGS As Long = SWP_NOZORDER Or _
SWP_NOSIZE Or _
SWP_NOMOVE Or _
SWP_DRAWFRAME

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal Y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long



Private Sub Form_Load()
ListView1.View = lvwReport

ListView1.ColumnHeaders.Add , , "main"
ListView1.ColumnHeaders.Add , , "sub1"

ListView1.ColumnHeaders.Add , , "sub2"
ListView1.ListItems.Add , "test1", "test1"
ListView1.ListItems("test1").SubItems(1) = "test1-1"

ListView1.ListItems("test1").SubItems(2) = "test1-2"
ListView1.ListItems.Add , "test2", "test2"
ListView1.ListItems("test2").SubItems(1) = "test2-1"
ListView1.ListItems("test2").SubItems(2) = "test2-2"
ListView1.FullRowSelect = True
End Sub

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
MsgBox "FF"
End Sub



Private Sub Check1_Click()

Dim style As Long
Dim hHeader As Long

'get the handle to the listview header
hHeader = SendMessage(ListView1.hwnd, LVM_GETHEADER, 0, ByVal 0&)

'get the current style attributes for the header
style = GetWindowLong(hHeader, GWL_STYLE)

'modify the style by toggling the HDS_BUTTONS style
style = style Xor HDS_BUTTONS

'set the new style and redraw the listview
If style Then
Call SetWindowLong(hHeader, GWL_STYLE, style)
Call SetWindowPos(ListView1.hwnd, Form1.hwnd, 0, 0, 0, 0, SWP_FLAGS)
End If

End Sub




...全文

相关推荐

LVColHeader.rar_ListView

**ColumnClick事件**: 当用户单击ListView控件的列头时,该事件被触发。这通常是用来实现按所点击的列进行数据排序的关键。

alvarocfc

MFC控件开发实战:从基础原理到高级应用与避坑指南

本文系统讲解MFC控件开发的核心技术,涵盖基础控件(CStatic、CButton、CEdit)与高级控件(CListBox、CComboBox、CListCtrl、CTreeCtrl)的使用要点;深入DDX/DDV数据交换机制、动态控件创建及Windows消息处理;重点剖析多线程UI更新、闪烁优化、高DPI布局适配和控件自绘等实战避坑方案,聚焦Windows GUI编程底层原理与C++桌面开发稳定性需求。

weixin_30613727

VC++ MFC类库中文手册实战指南:从核心架构到高级编程

本文系统讲解VC++ MFC类库的核心架构与实战编程,重点涵盖文档-视图架构、消息机制、动态创建、序列化、CListCtrl/CTreeCtrl高级用法、CPropertySheet进阶技巧、MFC DLL类型差异、多线程安全实践及调试优化方法。强调中文手册在遗留系统维护与高性能Windows桌面开发中的不可替代价值,并提供避坑指南与兼容性处理方案。

weixin_34056162

WIN32汇编 listview排序源码

**ListView排序机制** 在Windows API中,ListView的排序功能通常是通过响应LVN_COLUMNCLICK通知来实现的。

wuyelianqu

vb6源码:ListView控件应用报表(有多种排列方式).rar

**列排序**:通过处理ListView的ColumnClick事件,可以实现在用户点击列头时按指定列进行升序或降序排序。这涉及到比较函数和数组操作,以便重新排序列表项。3.

做个作家
评论 2
收藏 已收藏
分享
返回顶部
laviewpbt
控件 1,453 成员 41,351 内容