如何设置让LISTVIEW不显示水平滚动条。高手进(这是我在CSDN上的第10个问题,前九个都没有解决)

Sandycs 2003-11-04 11:04:59
LISTVIEW有一个属性可以设置是否显示滚动条,但是我只需要垂直滚动条,水平滚动条很难看,该如何做?
另外,如何限制用户调整LISTVIEW中列的大小,因为水平滚动条的出现往往是用户调整列大小造成的。
最后,我研究发现LISTVIEW中调节列大小的鼠标事件无法捕获。用SPY++也看不出来。
...全文
1057 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sandycs 2003-11-10
  • 打赏
  • 举报
回复
一群笨蛋
水如烟 2003-11-10
  • 打赏
  • 举报
回复
呵,多谢
Montaque 2003-11-10
  • 打赏
  • 举报
回复
设置column不可以resize.
Montaque 2003-11-10
  • 打赏
  • 举报
回复
呵呵,可以解决的.
Imports System.Runtime.InteropServices

Public Class ListViewEx
Inherits System.Windows.Forms.ListView

' Constants passed to the Scroll event
Public Enum ScrollDirection
Horizontal = 0
Vertical
End Enum

' Window messages we need to intercept
Private Enum WindowMessages As Integer
WM_HSCROLL = &H114
WM_NOTIFY = &H4E
WM_VSCROLL = &H115
End Enum

' Notification messages for WM_NOTIFY
Private Enum HeaderNotifications As Integer
HDN_FIRST = -300&
HDN_BEGINTRACK = (HDN_FIRST - 26) ' Begin Column resize
HDN_ENDTRACK = (HDN_FIRST - 27) ' End Column resize
HDN_DIVIDERDBLCLICK = (HDN_FIRST - 25) ' Double-click on divider
HDN_ITEMCHANGING = (HDN_FIRST - 20) ' Column resizing
End Enum

' Structure to hold extra information for WM_NOTIFY messages
<StructLayout(LayoutKind.Sequential)> Private Structure NMHDR
Friend hWndFrom As Integer
Friend idfrom As Integer
Friend code As Integer
End Structure

Protected mblnAllowColumnResize As Boolean = True

Public Event ColumnsResized(ByVal sender As Object)
Public Event Scroll(ByVal sender As Object, _
ByVal Direction As ScrollDirection)
'***********************************************************************
' Public Sub New()
' Description: Class constructor
'***********************************************************************
Public Sub New()
MyBase.New()
End Sub
'***********************************************************************
' Protected Overridable Sub OnColumnHeaderResized()
' Description: Performs actions and raises events when a ListView
' column is resized.
'***********************************************************************
Protected Overridable Sub OnColumnHeaderResized()
RaiseEvent ColumnsResized(Me)
End Sub
'***********************************************************************
' Protected Overridable Sub OnScroll(ByVal Direction As
ScrollDirection)
' Description: Performs actions and raises events when the ListView
is
' scrolled.
'***********************************************************************
Protected Overridable Sub OnScroll(ByVal Direction As
ScrollDirection)
RaiseEvent Scroll(Me, Direction)
End Sub
'***********************************************************************
' Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
' Description: Handles Windows messages
'***********************************************************************
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)

' Execute parent WndProc. While we're subclassing anyway, we'll
' encapsulate it in a Try block so that we can catch that annoying
' NullReferenceException that gets thrown occasionally during a
' LabelEdit. NOTE: This may only be necessary in Beta 2.
Try
MyBase.WndProc(m)
Catch
Exit Sub
End Try

Select Case m.Msg

' Catch scroll messages and fire the Scroll event
Case WindowMessages.WM_HSCROLL :
OnScroll(ScrollDirection.Horizontal)
Case WindowMessages.WM_VSCROLL :
OnScroll(ScrollDirection.Vertical)

' Information about Column resizing comes throught WM_NOTIFY
Case WindowMessages.WM_NOTIFY

' Read in the NMHDR structure from LParam
With CType(m.GetLParam(GetType(NMHDR)), NMHDR)

' See what kind of notification we're dealing with...
Select Case .code

' The user is starting to drag-resize -- abort if not
allowed
Case HeaderNotifications.HDN_BEGINTRACK
If mblnAllowColumnResize = False Then m.Result = New
IntPtr(1)

' A header is being resized -- fire the event, or abort
Case HeaderNotifications.HDN_ITEMCHANGING
Select Case mblnAllowColumnResize
Case True : OnColumnHeaderResized() ' Fire the event
Case False : m.Result = New IntPtr(1) ' Abort
End Select
End Select
End With
End Select
End Sub
'*********************************************************************
' Public Property AllowColumnResize() As Boolean
' Description: Returns/sets a value which determines whether
ListView
' columns can be resized, either manually or in code.
' NOTE: Setting this property to False prevents resizing Columns
using
' their Width property as well as manually.
'*********************************************************************
Public Property AllowColumnResize() As Boolean
Get
Return mblnAllowColumnResize
End Get
Set(ByVal Value As Boolean)
mblnAllowColumnResize = Value
End Set
End Property
End Class
Sandycs 2003-11-07
  • 打赏
  • 举报
回复
晕倒
都是菜鸟吗?
abiho 2003-11-06
  • 打赏
  • 举报
回复
现在问题是怎样获得调整列宽的事件了
有api么
Sandycs 2003-11-06
  • 打赏
  • 举报
回复
动态改变LISTVIEW宽度一点也不难
困难在于无知的用户自己会把它拉来拉去,然后又抱怨我们出现滚动条不爽
Sandycs 2003-11-06
  • 打赏
  • 举报
回复
好吧
上面3个说的
HENRYFAN1,一开始我就想重写控件,但是从来没有找到该重写哪个函数
LZ305你说给控件发消息,是啥消息,能否具体讲出
ITLEON TREEVIEW确实更复杂,只是我大部分都已经用LISTVIEW编写完成,再用TREEVIEW工作量比较大。
Sandycs 2003-11-06
  • 打赏
  • 举报
回复
不知道哪个API是
MSDN太庞大了,不好查啊
Sandycs 2003-11-05
  • 打赏
  • 举报
回复
第10个未解决的问题
唉~~~准备结贴了

良朋 2003-11-05
  • 打赏
  • 举报
回复
TreeView是比ListView 更复杂的东东,你可以研究一下,一楼的同志可能笔误了,不要责怪。
他的意思可是你让你动态改变ListView的宽度以适应列的大小,这样水平滚动条就不会出来了。
何必为滚动条纠缠不清呢。
lz305 2003-11-05
  • 打赏
  • 举报
回复
给控件发消息
henryfan1 2003-11-05
  • 打赏
  • 举报
回复
ListView是没你所讲的功能,
可以重写控件实现:(
Sandycs 2003-11-04
  • 打赏
  • 举报
回复
不知道一楼的在说什么
“在这种情况下”不知道说的是什么情况
“tiewview”是什么冬冬,弄不明白
不会回答呢,我知道你们和热心,顶一顶就可以了,不要不知道乱说
NoReady 2003-11-04
  • 打赏
  • 举报
回复
1、在这种情况下,你只能改变tiewview的大小

16,557

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧