VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Procedures to autofit text into a listview (reportview) control and to sort a listview by column.

by Ralph Ligtenberg (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 31st May 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Procedures to autofit text into a listview (reportview) control and to sort a listview by column.

API Declarations





Rate Procedures to autofit text into a listview (reportview) control and to sort a listview by column.



'Name:        ListView procedures
'
'Author:      Ralph Ligtenberg ([email protected])
'Copyright:   2000, Wortell
'
'Modified:    2000-05-31
'
'Description: Contains procedures to manipulate ListViews.
'
'Usage:       See procedures for more details.



Public Sub ListviewSort(ByRef View As ListView, ByVal Column As Integer)
  'Sorts the list depending on specified column
  
  If View.SortKey <> Column - 1 Then
    View.ColumnHeaders(View.SortKey + 1).Text = _
          Left(View.ColumnHeaders(View.SortKey + 1).Text, 1) _
          & LCase(Mid(View.ColumnHeaders(View.SortKey + 1).Text, 2))
    View.ColumnHeaders(Column).Text = UCase(View.ColumnHeaders(Column).Text)
    View.SortKey = Column - 1
  End If
End Sub

Public Sub ListviewAutoFit(ByRef List As ListView, _
                           ByRef AutosizeLabel As Label)
  'Automatically resizes listview columns so that all text
  'is visible. If the column name is empty, the column will
  'be resized to 0.
  'To make this procedure work properly, AutosizeLabel must
  'have the following settings:
  '   - Font has to be the same as the Listview's
  '   - Visible = False
  '   - AutoSize = True
  Dim i As Long
  Dim j As Long
  Dim State As Boolean
  
  With List
    State = .Visible
    .Visible = False
    
    For i = 1 To .ColumnHeaders.Count
      If .ColumnHeaders(i).Text <> "" Then
        AutosizeLabel.Caption = .ColumnHeaders(i).Text
        .ColumnHeaders(i).Width = AutosizeLabel.Width + 280
        For j = 1 To .ListItems.Count
          If i = 1 Then
            AutosizeLabel.Caption = .ListItems(j) _
                                  & IIf(.Icons Is Nothing, "", "XX")
          Else
            AutosizeLabel.Caption = .ListItems(j).SubItems(i - 1)
          End If
          
          If .ColumnHeaders(i).Width < AutosizeLabel.Width + 280 Then
            .ColumnHeaders(i).Width = AutosizeLabel.Width + 280
          End If
        Next
      Else
        .ColumnHeaders(i).Width = 0
      End If
    Next
    
    .Visible = State
  End With
End Sub




Download this snippet    Add to My Saved Code

Procedures to autofit text into a listview (reportview) control and to sort a listview by column. Comments

No comments have been posted about Procedures to autofit text into a listview (reportview) control and to sort a listview by column.. Why not be the first to post a comment about Procedures to autofit text into a listview (reportview) control and to sort a listview by column..

Post your comment

Subject:
Message:
0/1000 characters