Home > Software engineering >  Listview hidden column method
Listview hidden column method

Time:09-19

Requirements: hide the column width of 0, and it cannot be pulled display, realize the real hidden,
Existing methods can only through the API fixed all columns can't drag, so solving
Option Explicit

The Public Type NMHDR
HwndFrom As Long
IdFrom As Long
Code As Long
End Type

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any Source, As Any, ByVal Length As Long)
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam) As Long As Long
Public Const GWL_WNDPROC=(4)
Public Const WM_NOTIFY=& amp; H4E

Public Const HDN_FIRST=- 300
Public Const HDN_DIVIDERDBLCLICKA=HDN_FIRST - 5
Public Const HDN_DIVIDERDBLCLICKW=HDN_FIRST - 25
Public Const HDN_BEGINTRACKA=HDN_FIRST - 6
Public Const HDN_BEGINTRACKW=HDN_FIRST - 26

Private lpPrevWndFunc As Long

The Public Function WindowProc (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam) As Long As Long
The Select Case uMsg
Case WM_NOTIFY
Dim X As NMHDR
CopyMemory X, ByVal lParam, Len (X)
If X.c ode=HDN_BEGINTRACKA Or X.c ode=HDN_BEGINTRACKW Or _
X.c ode=HDN_DIVIDERDBLCLICKA Or _
X.c ode=HDN_DIVIDERDBLCLICKW Then
WindowProc=1
The Exit Function
End the If
End the Select
WindowProc=CallWindowProc (lpPrevWndFunc hWnd, uMsg, wParam, lParam)
End the Function

Public Sub LockHead (ByVal hWnd As Long)
LpPrevWndFunc=SetWindowLong (hWnd GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub UnLockHead (ByVal hWnd As Long)
SetWindowLong hWnd GWL_WNDPROC, lpPrevWndFunc
End Sub

Call: Call LockHead (Listview1 hWnd)
Call UnLockHead (Listview1 hWnd)

CodePudding user response:

Convenient debugging instances: http://pan.baidu.com/s/1kVj5kQb

CodePudding user response:

The ListView control


The ListView control can use four different view shows the project, through this control, the project can be formed with or without column header of the column, and displays the ICONS and text, with

Syntax

ListView

Description

Can use the ListView control organization called the ListItem object list items into one of the four different views of the following:

Large (standard) icon


Small icon


A list


The report
View attributes to determine what View shows items in a list control use, can also be used LabelWrap properties associated with the project control list tags can, according to a new line in addition, may also the ranking method of project management list and the appearance of the selected project,

ListView control including ListItem and ColumnHeader objects, ListItem object definitions in the ListView control various features of the project, such as:

A brief description of the project,


Together with the project provided by the ImageList control icon,


Additional text fragment, called subprojects, they are linked to show the ListItem object in the report view,
Can use HideColumnHeaders attribute determines whether the ListView control is shown in the column header, column headers can be added at design time, also can be added at runtime, the design, use the ListView control "attributes" dialog "column of the first" TAB to Add column headers, run time, use the Add method ColumnHeader objects is added to the ColumnHeaders collection,

Issued notice the ListView control is Mscomctl. The part of a group of ActiveX controls ocx files, if you want to use the ListView control in your application, you must will Mscomctl. Ocx files added to the project, when issuing the application, please submit Mscomctl. Ocx files installed to the users of Microsoft Windows System or System32 directory, on how to add ActiveX controls to the Visual Basic project detailed information, please refer to the Visual Basic "programmers guide,"

CodePudding user response:

Change the idea, don't want to be seen why data must be put in listview inside? The purpose is to let the customer to choose a line when you get this hidden data, add the column of data to the corresponding array or collection it can also realize,

You send examples of statement and form the load change a little, add a item by click on the event, demonstrate the hidden columns,
In the item just don't forget to add and delete synchronous change the contents of the collection inside,

 

Dim colHideCol As New Collection 'collections are used to define a module level for hidden things
Private Sub Form_Load ()
Dim As Integer I
Dim mRow As ListItem
Me. The ScaleMode=vbTwips
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
'initialize
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lv. View=lvwReport
Lv. FullRowSelect=True
Lv. Checkboxes=True
Lv. ColumnHeaders. Add,,
"serial number"Lv. ColumnHeaders. Add,, "title"
Lv. ColumnHeaders. Add,, "1" title, 0 'this column width of 0 but can be opened

For I=1 To colHideCol. Count 'initialization To empty the
ColHideCol. Remove (1)
Next
For I=0 To 40
The Set mRow=lv. ListItems. Add (,, CStr (I))
MRow. SubItems (1)="welcome to the pillow good website, thank you" & amp; I
ColHideCol. Add "column is not displayed" & amp; I, "K" & amp; MRow. The Index 'here don't want to display a collection of columns in the synchronous processing
Next

Lv. ListItems (3). Checked=True
Lv. ListItems (5). Checked=True
Lv. ListItems (13). Checked=True
Lv. ListItems (23). Checked=True
Lv. ListItems (6). Checked=True
Lv. ListItems (9). Checked=True


End Sub


Private Sub lv_ItemClick (ByVal Item As MSComctlLib. ListItem)
MsgBox "the hidden content:" & amp; ColHideCol. Item (" K "& amp; Item. The Index)
End Sub

CodePudding user response:

I want to achieve is can at any time by setting a column column width to achieve the purpose of to hide and display.

CodePudding user response:

Change control, such as the Xtreme SuitePro Report of ActiveX controls, directly to fulfill your requirements,

CodePudding user response:

Control ready, want to have a function, can choose to display the column, is poor this feature, you can help out an idea, my generation to change it nullnullnull
  •  Tags:  
  • API
  • Related