Attribute VB_Name = "ListCtrlDemoModule" Option Explicit '---------------------------------------------------------- 'ListCtrl Demo 'This demo shows all the operations that can be performed 'on a WS_LISTCTRL widget '---------------------------------------------------------- Public wsRfFile As New RFFILE Public wsFactory As New WStFactory Public wsForm As New WStForm Public wsWidget As New WStWidget Public wsError As New WStError Public Sub Main() Dim bResult As Boolean Dim sObjectName As String Dim sEventValue As String Dim sIntVal As String Dim bEnd As Boolean Dim iEventCount As Integer Dim iIconId As Integer Dim iSelectedRow As Integer Dim iSelectedColumn As Integer Dim sRemoteTempFolder As String Dim x As Integer Dim y As Integer Dim cx As Integer Dim cy As Integer x = 0 y = 0 cx = 0 cy = 0 bEnd = False 'Form creation and customization wsFactory.CreateFormByName "listCtrlForm" wsForm.SetCoordTypeByName "listCtrlForm", WS_FORM_CT_BYPERCENTAGE 'Widget Creation x = 3 wsFactory.CreateWidget WS_LABEL, 0, "FormTittle", 35, 0, 40, 5, "ListCtrl Demo" wsFactory.CreateWidget WS_LABEL, 0, "eventResult", x, 6, 90, 5, "" wsFactory.CreateWidget WS_LIST_CTRL, 0, "myListCtrl", x, 12, 60, 50, "" wsFactory.CreateWidget WS_BUTTON, 0, "exitButton", x, 80, 29, 12, "Exit" wsFactory.CreateWidget WS_BUTTON, 0, "resetFormBtn", 33, 80, 32, 12, "Reset" 'Right controls x = 66 y = 10 cx = 31 cy = 6 wsFactory.CreateWidget WS_LABEL, 0, "newRowTextLabel", x, y, cx, cy, "Row Text:" wsFactory.CreateWidget WS_FIELD, 0, "newRowTextField", x, y + cy, cx, cy, "" wsFactory.CreateWidget WS_LABEL, 0, "newRowIconLabel", x, y + 2 * cy + 1, cx, cy, "Row Icon:" wsFactory.CreateWidget WS_MENU, 0, "newRowIconComboBox", x, y + 3 * cy + 1, cx, cy + 30, "" 'Buttons x = 66 y = y + 4 * cy + 3 cx = 31 cy = 10 wsFactory.CreateWidget WS_BUTTON, 0, "deleteRowBtn", x, y, cx, cy, "Delete Sel. Row" wsFactory.CreateWidget WS_BUTTON, 0, "loadRowsFromDataBtn", x, y + cy, cx, cy, "Load data from file" wsFactory.CreateWidget WS_BUTTON, 0, "clearColumnsBtn", x, y + 2 * cy, cx, cy, "Clear Columns" wsFactory.CreateWidget WS_BUTTON, 0, "clearRowsBtn", x, y + 3 * cy, cx, cy, "Clear Rows" wsFactory.CreateWidget WS_BUTTON, 0, "paintBtn", x, y + 4 * cy, cx, cy, "Paint Rows!" 'Check Box x = 66 y = y + 5 * cy cx = 31 cy = 10 wsFactory.CreateWidget WS_CHECKBOX, 0, "sortCheckBox", x, y, cx, cy, "Sorteable" 'Font selection controls x = 5 y = 63 cx = 60 cy = 5 wsFactory.CreateWidget WS_LABEL, 0, "listCtrlFontLabel", x, y, cx, cy, "Font:" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "timesNRomanFontRdBtn", x, y + cy, cx, cy, "Times New Roman" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "tahomaFontRdBtn", x, y + 2 * cy, cx, cy, "Tahoma" wsWidget.ChangeMenuTypeByName "newRowIconComboBox", WS_COMBO_BOX_MENU_TYPE wsWidget.AddOptionByName "newRowIconComboBox", 0, "None" wsWidget.AddOptionByName "newRowIconComboBox", 0, "Ok" wsWidget.AddOptionByName "newRowIconComboBox", 0, "Box" 'Icons wsFactory.LoadExternalIcon 3, WS_EXIT, "iconlib.dll" wsFactory.LoadExternalIcon 6, WS_RELOAD, "iconlib.dll" 'Icons used on the list control, you can load more and use the widget newRowIconComboBox to change 'them dinamycally wsFactory.LoadExternalIcon 1, WS_OK, "iconlib.dll" wsFactory.LoadExternalIcon 2, WS_BOX, "iconlib.dll" wsWidget.SetIconByName "exitButton", 3 wsWidget.SetIconByName "resetFormBtn", 6 'Fonts wsFactory.CreateCustomFont 1, 14, True, False, False, "Times New Roman", 0 wsFactory.CreateCustomFont 2, 20, False, True, False, "Tahoma", 0 wsFactory.CreateCustomFont 3, 10, False, False, True, "Times New Roman", 0 wsFactory.CreateCustomFont 4, 11, False, False, False, "Arial", 0 'Widgets attachment wsForm.AddObjectByName "listCtrlForm", "FormTittle" wsForm.AddObjectByName "listCtrlForm", "exitButton" wsForm.AddObjectByName "listCtrlForm", "myListCtrl" wsForm.AddObjectByName "listCtrlForm", "eventResult" wsForm.AddObjectByName "listCtrlForm", "newRowTextLabel" wsForm.AddObjectByName "listCtrlForm", "newRowTextField" wsForm.AddObjectByName "listCtrlForm", "newRowIconLabel" wsForm.AddObjectByName "listCtrlForm", "newRowIconComboBox" wsForm.AddObjectByName "listCtrlForm", "deleteRowBtn" wsForm.AddObjectByName "listCtrlForm", "timesNRomanFontRdBtn" wsForm.AddObjectByName "listCtrlForm", "loadRowsFromDataBtn" wsForm.AddObjectByName "listCtrlForm", "listCtrlFontLabel" wsForm.AddObjectByName "listCtrlForm", "resetFormBtn" wsForm.AddObjectByName "listCtrlForm", "clearRowsBtn" wsForm.AddObjectByName "listCtrlForm", "tahomaFontRdBtn" wsForm.AddObjectByName "listCtrlForm", "clearColumnsBtn" wsForm.AddObjectByName "listCtrlForm", "paintBtn" wsForm.AddObjectByName "listCtrlForm", "sortCheckBox" 'Widgets customization 'The data file that can be asociated with the list ctrl sRemoteTempFolder = wsRfFile.GetRemoteTempFolder wsRfFile.RFTransferFile "..\SamplesWidgets\Exe\Resources\data.txt", _ sRemoteTempFolder + "\data.txt", True wsWidget.SetGroupIdByName "timesNRomanFontRdBtn", 1 wsWidget.SetGroupIdByName "tahomaFontRdBtn", 1 wsWidget.SetFontByName "FormTittle", 1 wsWidget.SetFontByName "exitButton", 1 wsWidget.AddColumnByName "myListCtrl", 30, "Column1" wsWidget.AddColumnByName "myListCtrl", 30, "Column2" wsWidget.AddColumnByName "myListCtrl", 30, "Column3" wsWidget.AddColumnByName "myListCtrl", 30, "Column4" wsWidget.AddColumnByName "myListCtrl", 30, "Column5" 'Adds 5 rows and sets their icons wsWidget.AddRowByName "myListCtrl", 1 wsWidget.AddRowByName "myListCtrl", 2 wsWidget.AddRowByName "myListCtrl", 0 wsWidget.AddRowByName "myListCtrl", 0 wsWidget.AddRowByName "myListCtrl", 1 wsWidget.SetRowTextByName "myListCtrl", 0, 0, "R0C0" wsWidget.SetRowTextByName "myListCtrl", 1, 1, "R1C1" wsWidget.SetRowTextByName "myListCtrl", 2, 2, "R2C2" wsWidget.SetRowTextByName "myListCtrl", 3, 3, "R3C3" wsWidget.SetRowTextByName "myListCtrl", 4, 4, "R4C4" wsWidget.SetFontByName "eventResult", 4 bResult = wsForm.ShowByName("listCtrlForm", True, True) bEnd = False 'Waits for an event and perform an action While (bEnd = False And bResult) bResult = wsForm.GetEvent() sObjectName = wsForm.GetLastEventSourceName() Select Case sObjectName Case "exitButton" wsForm.EndCurrentForm GoTo EndProgram Case "myListCtrl" If wsWidget.GetLastClickEventTypeByName("myListCtrl") = WS_CLICK_EVENT_ON_ITEM Then iSelectedRow = wsWidget.GetSelectedItemByName("myListCtrl") sIntVal = iSelectedRow sEventValue = "Row: " + sIntVal + " Str: " + _ wsWidget.GetRowTextByName("myListCtrl", iSelectedRow, 0) ElseIf wsWidget.GetLastClickEventTypeByName("myListCtrl") = WS_CLICK_EVENT_ON_HEADER Then sIntVal = wsWidget.GetSelectedColumnByName("myListCtrl") sEventValue = "Column: " + sIntVal End If wsWidget.SetTextByName "eventResult", sEventValue Case "newRowTextField" sEventValue = wsForm.GetLastEventStrValue() 'Changes the text of the first column of a previously selected row If wsWidget.GetSelectedItemByName("myListCtrl") <> -1 Then If Not wsWidget.SetRowTextByName("myListCtrl", wsWidget.GetSelectedItemByName("myListCtrl"), _ 0, sEventValue) Then ShowErrorMessage End If End If Case "newRowIconComboBox" 'Changes the icon of a previously selected row iIconId = wsForm.GetLastEventIntValue() If wsWidget.GetSelectedItemByName("myListCtrl") <> -1 Then wsWidget.SetRowIconByName "myListCtrl", wsWidget.GetSelectedItemByName("myListCtrl"), _ iIconId End If Case "deleteRowBtn" 'Deletes a previously selected row If wsWidget.GetSelectedItemByName("myListCtrl") <> -1 Then If Not wsWidget.DeleteRowByName("myListCtrl", wsWidget.GetSelectedItemByName("myListCtrl")) Then ShowErrorMessage End If End If Case "loadRowsFromDataBtn" 'Fulfills the WS_LISTCTRL widget using the data.txt file wsWidget.SetLoadModeByName "myListCtrl", WS_LIST_CTRL_LOAD_FROM_FILE If Not wsWidget.ReadRowsFromFileByName("myListCtrl", "..\SamplesWidgets\Exe\Resources\data.txt", _ sRemoteTempFolder + "\data.txt") Then ShowErrorMessage End If Case "resetFormBtn" 'Reloads the form from the file storaged in the MU wsForm.RestoreInitialState Case "clearColumnsBtn" 'Removes the columns of the list ctrl wsWidget.ClearColumnsByName "myListCtrl" Case "clearRowsBtn" 'Clears the rows of the list ctrl If Not wsWidget.ClearRowsByName("myListCtrl") Then ShowErrorMessage End If Case "sortCheckBox" If wsWidget.GetStateByName("sortCheckBox") = WS_STATE_CHECKED Then wsWidget.SetSortModeByName "myListCtrl", WS_LIST_CTRL_SORT_DESCENDING + _ WS_LIST_CTRL_SORT_ASCENDING Else wsWidget.SetSortModeByName "myListCtrl", WS_LIST_CTRL_SORT_DISABLED End If Case "paintBtn" Paint 206, 219, 247 End Select If wsWidget.GetStateByName("tahomaFontRdBtn") = WS_STATE_CHECKED Then wsWidget.SetFontByName "myListCtrl", 2 End If If wsWidget.GetStateByName("timesNRomanFontRdBtn") = WS_STATE_CHECKED Then wsWidget.SetFontByName "myListCtrl", 3 End If Wend EndProgram: End Sub Public Sub ShowErrorMessage() wsForm.ShowMessageBox wsError.GetLastErrorDescription, "ListCtrl Demo", WS_MSG_BOX_OP_OK, 0, _ WS_MSG_BOX_ICON_ERROR End Sub Public Sub Paint(iRed As Integer, iGreen As Integer, iBlue As Integer) Dim i, iRows As Integer iRows = wsWidget.GetItemCountByName("myListCtrl") For i = 0 To iRows - 1 If i Mod 2 = 0 Then wsWidget.SetRowBackgroundColorByName "myListCtrl", i, iRed, iGreen, iBlue End If Next i End Sub