Attribute VB_Name = "modListView5" Option Explicit ' ' '============================================================================================================= ' modListView5 Module ' ------------------- ' ' Created By : Kevin Wilson ' http://www.TheVBZone.com ( The VB Zone ) ' http://www.TheVBZone.net ( The VB Zone .net ) ' ' Last Update : December 13, 2001 ' ' VB Versions : 5.0 / 6.0 ' ' Requires : COMCTL32.OCX (Microsoft Windows Common Controls 5.0) ' ' Description : This module makes it easy to turn the "ListView" control that comes with the Windows Common ' Controls 5.0 library into a spread sheet control that looks similar to Excel or Quatro Pro. ' The usage of the ListView control alone is rather odd, so this module makes it very easy ' and straight forward to use. ' ' Example Use : ' ' Private Sub Form_Load() ' Dim lngErrNum As Long ' Dim strErrDesc As String ' ListView_Initialize LV, , , , , , , , , , , , , lngErrNum, strErrDesc: GoSub CheckForError ' ListView_AddColumn LV, "Column Header 1", , "Col1", , , , , , lngErrNum, strErrDesc: GoSub CheckForError ' ListView_AddColumn LV, "Column Header 2", , "Col2", , , , , , lngErrNum, strErrDesc: GoSub CheckForError ' ListView_AddColumn LV, "Column Header 3", , "Col3", , , , , , lngErrNum, strErrDesc: GoSub CheckForError ' ListView_AddRow LV, , , "Row1", , , , , lngErrNum, strErrDesc: GoSub CheckForError ' ListView_AddRow LV, , , "Row2", , , , , lngErrNum, strErrDesc: GoSub CheckForError ' ListView_AddRow LV, , , "Row3", , , , , lngErrNum, strErrDesc: GoSub CheckForError ' ListView_ModifyRow LV, "1-1", , , "Row1", 0, lngErrNum, strErrDesc: GoSub CheckForError ' ListView_ModifyRow LV, "1-2", , 0, , 1, lngErrNum, strErrDesc: GoSub CheckForError ' ListView_ModifyRow LV, "1-3", , 0, , 2, lngErrNum, strErrDesc: GoSub CheckForError ' ListView_ModifyRow LV, "2-1", , 1, , 0, lngErrNum, strErrDesc: GoSub CheckForError ' ListView_ModifyRow LV, "2-2", , 1, , 1, lngErrNum, strErrDesc: GoSub CheckForError ' ListView_ModifyRow LV, "3-1", , 2, , 0, lngErrNum, strErrDesc: GoSub CheckForError ' ListView_ModifyColumn LV, "New 1", , 0, , lngErrNum, strErrDesc: GoSub CheckForError ' ListView_ModifyColumn LV, "New 2", , , "Col2", lngErrNum, strErrDesc: GoSub CheckForError ' Exit Sub ' 'CheckForError: ' ' If lngErrNum <> 0 Then ' MsgBox "An error occured while working with the ListView control named 'LV':" & Chr(13) & Chr(13) & "Error Number = " & CStr(lngErrNum) & Chr(13) & "Error Description = " & strErrDesc, vbOKOnly + vbExclamation, " Error" ' Else ' Return ' End If ' End Sub ' ' Private Sub LV_ColumnClick(ByVal ColumnHeader As ComctlLib.ColumnHeader) ' Event_ColumnClick LV, ColumnHeader ' End Sub ' '============================================================================================================= ' ' LEGAL: ' ' You are free to use this code as long as you keep the above heading information intact and unchanged. Credit ' given where credit is due. Also, it is not required, but it would be appreciated if you would mention ' somewhere in your compiled program that that your program makes use of code written and distributed by ' Kevin Wilson (www.TheVBZone.com). Feel free to link to this code via your web site or articles. ' ' You may NOT take this code and pass it off as your own. You may NOT distribute this code on your own server ' or web site. You may NOT take code created by Kevin Wilson (www.TheVBZone.com) and use it to create products, ' utilities, or applications that directly compete with products, utilities, and applications created by Kevin ' Wilson, TheVBZone.com, or Wilson Media. You may NOT take this code and sell it for profit without first ' obtaining the written consent of the author Kevin Wilson. ' ' These conditions are subject to change at the discretion of the owner Kevin Wilson at any time without ' warning or notice. Copyrightİ by Kevin Wilson. All rights reserved. ' '============================================================================================================= '============================================================================================================= ' ListView_Initialize ' ' Initializes the specified ListView control and by default sets it up as a ListBox with column headers. ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to initialize ' Appearance Optional. Specifies whether or not controls, Forms or an MDIForm are painted at run time with 3-D effects. ' Arrange Optional. Specifies how the icons in a ListView control's Icon or SmallIcon view are arranged. ' BorderStyle Optional. Specifies the border style for an object. ' HideColumnHeaders Optional. Specifies whether or not a ListView control's column headers are hidden in Report view. ' HideSelection Optional. Determines whether the selected item will display as selected when the ListView loses focus ' ImageList Optional. Specifies the ImageList control to be used for ColumnHeader icons. ' LabelEdit Optional. Specifies a value that determines if a user can edit the label of a ListItem or Node object. ' LabelWrap Optional. Specifies a value that determines if labels are wrapped when the ListView is in Icon view. ' MultiSelect Optional. Specifies a value indicating whether a user can make multiple selections in the ListView control and how the multiple selections can be made. ' Sorted Optional. Indicates whether the elements of a control are automatically sorted alphabetically. ' SortOrder Optional. Specifies whether or not the ListItems will be sorted in ascending or descending order. ' View Optional. Specifies the current view of the ListView control. ' Return_ErrNum Optional. If an error occurs, this parameter will return the number of the error that occured ' Return_ErrDesc Optional. If an error occurs, this parameter will return the description of the error that occured ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_Initialize(ByRef lstControl As ComctlLib.ListView, _ Optional ByVal Appearance As ComctlLib.AppearanceConstants = cc3D, _ Optional ByVal Arrange As ComctlLib.ListArrangeConstants = lvwAutoLeft, _ Optional ByVal BorderStyle As ComctlLib.BorderStyleConstants = ccNone, _ Optional ByVal HideColumnHeaders As Boolean = False, _ Optional ByVal HideSelection As Boolean = False, _ Optional ByRef ImageList As Object, _ Optional ByVal LabelEdit As ComctlLib.ListLabelEditConstants = lvwManual, _ Optional ByVal LabelWrap As Boolean = True, _ Optional ByVal MultiSelect As Boolean = False, _ Optional ByVal Sorted As Boolean = False, _ Optional ByVal SortOrder As ComctlLib.ListSortOrderConstants = lvwAscending, _ Optional ByVal View As ComctlLib.ListViewConstants = lvwReport, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear the return variables Return_ErrNum = 0 Return_ErrDesc = "" ' Validate the parameters If lstControl Is Nothing Then GoTo InvalidParameter ' Setup the ListView control With lstControl .Appearance = Appearance .Arrange = Arrange .BackColor = vbWindowBackground .BorderStyle = BorderStyle .Enabled = True .ForeColor = vbWindowText .HideColumnHeaders = HideColumnHeaders .HideSelection = HideSelection If Not ImageList Is Nothing Then Set .Icons = ImageList If Not ImageList Is Nothing Then Set .SmallIcons = ImageList .LabelEdit = LabelEdit .LabelWrap = LabelWrap .MultiSelect = MultiSelect .Sorted = Sorted .SortOrder = SortOrder .View = View End With ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_Initialize = True Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_Initialize' function" End Function '============================================================================================================= ' ListView_AddColumn ' ' Adds a column to the specified ListView control ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' strColumnLabel Optional. The text that should appear in the newly created column header ' intColumnIndex Optional. If NOT omited, specifies the number that uniquely identifies the column ' in the ListView control. The value of the Index property of an object can change ' when objects in the collection are reordered, such as when the user reorders the ' column headers. If you expect the Index property to change dynamically, it may ' be more useful to refer to objects in a collection by using the Key property. ' strColumnKey Optional. Specifies the KEY value to assign to the newly created column. This can ' be used in modifying or deleting this row in the future. ' intColumnWidth Optional. The default width of the column to create ' intColumnIcon Optional. The index of the icon in the associated ImageList control to assign to ' the newly created column ' Alignment Optional. The alignment of the column header label text (left, center, right, etc) ' Return_Column Optional. Returns a reference to the newly created column object ' Return_ColumnIndex Optional. Returns the index of the newly created column object ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_AddColumn(ByRef lstControl As ComctlLib.ListView, _ Optional ByVal strColumnLabel As String = " ", _ Optional ByVal intColumnIndex As Integer, _ Optional ByVal strColumnKey As String, _ Optional ByVal intColumnWidth As Single = 1200, _ Optional ByVal intColumnIcon As Integer, _ Optional ByVal Alignment As ComctlLib.ListColumnAlignmentConstants = lvwColumnCenter, _ Optional ByRef Return_Column As ComctlLib.ColumnHeader, _ Optional ByRef Return_ColumnIndex As Long, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear the return variables Set Return_Column = Nothing Return_ColumnIndex = 0 Return_ErrNum = 0 Return_ErrDesc = "" ' Validate the parameters strColumnKey = Trim(strColumnKey) If lstControl Is Nothing Then GoTo InvalidParameter ' Make sure that once columns are added, that they are made visible lstControl.HideColumnHeaders = False ' Add the rows If intColumnIndex > 0 Then If lstControl.ColumnHeaders.Count <= 0 Then Set Return_Column = lstControl.ColumnHeaders.Add(intColumnIndex, strColumnKey, strColumnLabel, intColumnWidth, lvwColumnLeft) Else Set Return_Column = lstControl.ColumnHeaders.Add(intColumnIndex, strColumnKey, strColumnLabel, intColumnWidth, Alignment) End If Else If lstControl.ColumnHeaders.Count <= 0 Then Set Return_Column = lstControl.ColumnHeaders.Add(, strColumnKey, strColumnLabel, intColumnWidth, lvwColumnLeft) Else Set Return_Column = lstControl.ColumnHeaders.Add(, strColumnKey, strColumnLabel, intColumnWidth, Alignment) End If End If ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_AddColumn = True Return_ColumnIndex = Return_Column.Index End If Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_AddColumn' function" End Function '============================================================================================================= ' ListView_AddRow ' ' This function makes it easy to add a row to a ListView (Advanced ListBox) control ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' strValue Specifies the text value to put in the new row (value is put in the first column ' of the row). ' intIndex Optional. If NOT omited, specifies the number that uniquely identifies the row ' in the ListView control. The value of the Index property of an object can change ' when objects in the collection are reordered, such as when you set the Sorted ' property to True. If you expect the Index property to change dynamically, it may ' be more useful to refer to objects in a collection by using the Key property. ' strKey Optional. Specifies the KEY value to assign to the newly created row. This can ' be used in modifying or deleting this row in the future. ' intIndex_Icon Optional. Specifies the index of the image contained within an ImageList control ' that is associated with the ListView control being worked with. This image will ' be displayed if the ListView control's "View" property is set to "lvwIcon" (0). ' intIndex_SmallIcon Optional. Specifies the index of the image contained within an ImageList control ' that is associated with the ListView control being worked with. This image will ' be displayed if the ListView control's "View" property is set to anything but ' "lvwIcon". ' Return_RowCreated Optional. This parameter returns a refernce to the newly created row. This is ' meant to make it easy to modify the row in the future. ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if the function executes successfully ' Returns FALSE if the function fails ' '============================================================================================================= Public Function ListView_AddRow(ByRef lstControl As ComctlLib.ListView, _ Optional ByVal strValue As String, _ Optional ByVal intIndex As Integer, _ Optional ByVal strKey As String, _ Optional ByVal intIndex_Icon As Integer, _ Optional ByVal intIndex_SmallIcon As Integer, _ Optional ByRef Return_RowCreated As ComctlLib.ListItem, _ Optional ByRef Return_RowIndex As Long, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear return variables Set Return_RowCreated = Nothing Return_RowIndex = 0 Return_ErrNum = 0 Return_ErrDesc = "" ' Validate parameters strKey = Trim(strKey) If lstControl Is Nothing Then GoTo InvalidParameter ' Add the new row with the options specified If intIndex > 0 Then Set Return_RowCreated = lstControl.ListItems.Add(intIndex, strKey, strValue, intIndex_Icon, intIndex_SmallIcon) Else Set Return_RowCreated = lstControl.ListItems.Add(, strKey, strValue, intIndex_Icon, intIndex_SmallIcon) End If ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_AddRow = True Return_RowIndex = Return_RowCreated.Index End If Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_AddRow' function" End Function '============================================================================================================= ' ListView_Clear ' ' Removes all columns and rows in the specified ListView control ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_Clear(ByRef lstControl As ComctlLib.ListView, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear the return variables Return_ErrNum = 0 Return_ErrDesc = "" ' Validate the parameters If lstControl Is Nothing Then GoTo InvalidParameter ' Clear all rows and columns in the ListView control lstControl.ColumnHeaders.Clear lstControl.ListItems.Clear ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_Clear = True Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_Clear' function" End Function '============================================================================================================= ' ListView_ClearColumns ' ' Removes all columns in the specified ListView control ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_ClearColumns(ByRef lstControl As ComctlLib.ListView, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear the return variables Return_ErrNum = 0 Return_ErrDesc = "" ' Validate the parameters If lstControl Is Nothing Then GoTo InvalidParameter ' Clear all rows in the ListView control lstControl.ColumnHeaders.Clear ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_ClearColumns = True Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_ClearColumns' function" End Function '============================================================================================================= ' ListView_ClearRows ' ' Clears all the rows in the specified ListView control ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_ClearRows(ByRef lstControl As ComctlLib.ListView, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear the return variables Return_ErrNum = 0 Return_ErrDesc = "" ' Validate the parameters If lstControl Is Nothing Then GoTo InvalidParameter ' Clear all rows in the ListView control lstControl.ListItems.Clear ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_ClearRows = True Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_ClearRows' function" End Function '============================================================================================================= ' ListView_ModifyColumn ' ' Modifies the specified column header label ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' strValue Optional. Specifies the new text to asign to the specified column header ' lstColumnToModify Optional. Reference to the column header object to modify ' intColumnIndex Optional. The ZERO-BASED index of the column header object to modify ' strColumnKey Optional. The key of the column header object to modify ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_ModifyColumn(ByRef lstControl As ComctlLib.ListView, _ Optional ByVal strValue As String, _ Optional ByRef lstColumnToModify As ComctlLib.ColumnHeader, _ Optional ByVal intColumnIndex As Integer = -1, _ Optional ByVal strColumnKey As String, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear return variables Return_ErrNum = 0 Return_ErrDesc = "" ' Validate parameters strColumnKey = Trim(strColumnKey) If lstControl Is Nothing Then GoTo InvalidParameter If intColumnIndex <> -1 Then intColumnIndex = intColumnIndex + 1 If intColumnIndex > lstControl.ColumnHeaders.Count Or intColumnIndex < 1 Then GoTo InvalidParameter End If If lstColumnToModify Is Nothing And intColumnIndex < 1 And strColumnKey = "" Then GoTo InvalidParameter ' Modify the column header If Not lstColumnToModify Is Nothing Then lstColumnToModify.Text = strValue ElseIf strColumnKey <> "" Then lstControl.ColumnHeaders.item(strColumnKey).Text = strValue ElseIf intColumnIndex > 0 Then lstControl.ColumnHeaders.item(intColumnIndex).Text = strValue End If ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_ModifyColumn = True Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_ModifyColumn' function" End Function '============================================================================================================= ' ListView_ModifyRow ' ' Modifies the text of the specified row in the specified column ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' strValue Optional. The new text value to put in the specified row/column ' lstRowToModify Optional. Reference to the ListItem object to modify ' intRowIndex Optional. The ZERO-BASED index of the row to modify ' strRowKey Optional. The key of the row to modify ' intColumnIndex Optional. The ZERO-BASED column in the row to modify ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_ModifyRow(ByRef lstControl As ComctlLib.ListView, _ Optional ByVal strValue As String, _ Optional ByRef lstRowToModify As ComctlLib.ListItem, _ Optional ByVal intRowIndex As Integer = -1, _ Optional ByVal strRowKey As String, _ Optional ByVal intColumnIndex As Integer = -1, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear return variables Return_ErrNum = 0 Return_ErrDesc = "" ' Validate parameters strRowKey = Trim(strRowKey) If lstControl Is Nothing Then GoTo InvalidParameter If intColumnIndex <> -1 Then If intColumnIndex > lstControl.ColumnHeaders.Count Or intColumnIndex < 0 Then GoTo InvalidParameter If intRowIndex <> -1 Then intRowIndex = intRowIndex + 1 If intRowIndex > lstControl.ListItems.Count Or intRowIndex < 1 Then GoTo InvalidParameter End If If lstRowToModify Is Nothing And intRowIndex < 0 And strRowKey = "" Then GoTo InvalidParameter ' If the user wants to edit a column in the row, then do so If intColumnIndex > 0 Then If Not lstRowToModify Is Nothing Then If intColumnIndex = 0 Then lstRowToModify.Text = strValue Else lstRowToModify.SubItems(intColumnIndex) = strValue ElseIf strRowKey <> "" Then If intColumnIndex = 0 Then lstControl.ListItems.item(strRowKey).Text = strValue Else lstControl.ListItems.item(strRowKey).SubItems(intColumnIndex) = strValue ElseIf intRowIndex > 0 Then If intColumnIndex = 0 Then lstControl.ListItems.item(intRowIndex).Text = strValue Else lstControl.ListItems.item(intRowIndex).SubItems(intColumnIndex) = strValue End If ' The user wants to edit the row's valud (first column) Else If Not lstRowToModify Is Nothing Then lstRowToModify.Text = strValue ElseIf strRowKey <> "" Then lstControl.ListItems.item(strRowKey).Text = strValue ElseIf intRowIndex > 0 Then lstControl.ListItems.item(intRowIndex).Text = strValue End If End If ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_ModifyRow = True Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_ModifyRow' function" End Function '============================================================================================================= ' ListView_RemoveColumn ' ' Removes the specified column from the ListView control ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' intColumnIndex Optional. The index of the column to remove ' strColumnKey Optional. The key of the column to remove ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_RemoveColumn(ByRef lstControl As ComctlLib.ListView, _ Optional ByVal intColumnIndex As Integer, _ Optional ByVal strColumnKey As String, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear the return variables Return_ErrNum = 0 Return_ErrDesc = "" ' Validate the parameters strColumnKey = Trim(strColumnKey) If lstControl Is Nothing Then GoTo InvalidParameter If intColumnIndex < 1 And strColumnKey = "" Then GoTo InvalidParameter ' If there are no columns to delete, exit function If lstControl.ColumnHeaders.Count <= 0 Then ListView_RemoveColumn = True Exit Function End If ' Remove the specified column If intColumnIndex > 0 Then lstControl.ColumnHeaders.Remove intColumnIndex Else lstControl.ColumnHeaders.Remove strColumnKey End If ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_RemoveColumn = True Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_RemoveColumn' function" End Function '============================================================================================================= ' ListView_RemoveRow ' ' Removes the specified row and that row's contents ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' intRowIndex Optional. The index of the row to remove ' strRowKey Optional. The key of the row to remove ' Return_ErrNum Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error number that occured. ' Return_ErrDesc Optional. If an error occured in the creation of the ListView row, this parameter ' returns the error description that occured. ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Function ListView_RemoveRow(ByRef lstControl As ComctlLib.ListView, _ Optional ByVal intRowIndex As Integer, _ Optional ByVal strRowKey As String, _ Optional ByRef Return_ErrNum As Long, _ Optional ByRef Return_ErrDesc As String) As Boolean On Error Resume Next ' Clear return variables Return_ErrNum = 0 Return_ErrDesc = "" ' Validate parameters strRowKey = Trim(strRowKey) If lstControl Is Nothing Then GoTo InvalidParameter If intRowIndex < 1 And strRowKey = "" Then GoTo InvalidParameter ' If there are no rows to delete, exit function If lstControl.ListItems.Count <= 0 Then ListView_RemoveRow = True Exit Function End If ' Remove the specified row If intRowIndex < 1 Then lstControl.ListItems.Remove intRowIndex Else lstControl.ListItems.Remove strRowKey End If ' Check for errors Return_ErrNum = Err.Number Return_ErrDesc = Err.Description Err.Clear If Return_ErrNum = 0 Then ListView_RemoveRow = True Exit Function InvalidParameter: Return_ErrNum = -1 Return_ErrDesc = "Invalid parameter(s) passed to the 'ListView_RemoveRow' function" End Function 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '============================================================================================================= ' Event_ColumnClick ' ' Calling this function from with the "ColumnClick" event of the specified ListView control will give you ' the standard functionality of Columns where if you click on a column header, the ListView will be sorted ' by that row. ' ' Parameter Description ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ' lstControl A reference to the ListView control to work with ' ColumnHeader A reference to the Column Header clicked on. This is passed directly from the ' ColumnClick event paramter "ColumnHeader" ' ' Return: ' ŻŻŻŻŻŻŻ ' Returns TRUE if function succeeds ' Returns FALSE if function fails '============================================================================================================= Public Sub Event_ColumnClick(ByRef lstControl As ComctlLib.ListView, _ ByVal ColumnHeader As ComctlLib.ColumnHeader) On Error Resume Next Static LastSorted As Long lstControl.Sorted = True lstControl.SortKey = ColumnHeader.Index - 1 If ColumnHeader.Index - 1 = LastSorted Then If lstControl.SortOrder = lvwAscending = True Then lstControl.SortOrder = lvwDescending Else lstControl.SortOrder = lvwAscending End If End If LastSorted = ColumnHeader.Index - 1 End Sub