Announcement

Collapse
No announcement yet.

listview color on a single row

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • listview color on a single row

    I can change the background and forground colors of all the rows in a listview using %LVM_SETTEXTBKCOLOR and %LVM_SETTEXTCOLOR.

    I don't suppose there is an easy way to set the foreground/background for an indivitual row? I don't see anything directly in the LVM group in the win32 programmer's reference.

    I've looked at the samples here (specifically Erik's GRID.BAS), but it seems harder than it should be. Or is that just wishful thinking?

  • #2
    This is about as simple as it gets! - Copy Jose's code
    Code:
    #COMPILE EXE
    #DIM ALL
     
    #INCLUDE "WIN32API.INC"
    #INCLUDE "COMMCTRL.INC"
    %IDC_SYSLISTVIEW32_1    = 1001
    %BTN_BUTTON1            = 1002
    '------------------/
     
    CALLBACK FUNCTION MainProc()
     LOCAL lpNmh AS NMHDR PTR
     LOCAL lpLvNm AS NM_LISTVIEW PTR
     LOCAL lpLvCd AS NMLVCUSTOMDRAW PTR
     STATIC TestColour, CRow AS LONG 
     
      SELECT CASE CBMSG
        CASE %WM_COMMAND
          SELECT CASE CBCTL
            CASE %BTN_BUTTON1
              IF CBCTLMSG = %BN_CLICKED THEN
                TestColour = %TRUE
                CRow = 10
                CONTROL REDRAW CBHNDL, %IDC_SYSLISTVIEW32_1
              END IF
     
          END SELECT
     
        CASE %WM_NOTIFY                     ' Thanks To JOSE ROCA
          lpNmh = CBLPARAM
           SELECT CASE @lpNmh.idFrom
             CASE %IDC_SYSLISTVIEW32_1
               lpLvNm = CBLPARAM
               SELECT CASE @LpLvNm.hdr.code
                 CASE %NM_CUSTOMDRAW
                   lpLvCd = CBLPARAM
                   SELECT CASE @lplvcd.nmcd.dwDrawStage
                     CASE %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
                       FUNCTION = %CDRF_NOTIFYSUBITEMDRAW
                     CASE %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM
                       IF TestColour = %TRUE THEN
                         IF @lpLvCd.nmcd.dwItemSpec = CRow THEN   ' CRow = Row to be coloured
                            @lpLvCd.clrTextBk = RGB(180,247,250)
                            @lpLvCd.clrText = %BLACK
                         END IF
                       ELSE
                          @lpLvCd.clrTextBk = %WHITE 
                          @lpLvCd.clrText = %BLACK   
                       END IF
                      FUNCTION = %CDRF_NEWFONT
                   END SELECT
               END SELECT
           END SELECT
      END SELECT
     
    END FUNCTION
    '------------------/
     
    FUNCTION SampleListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL lColCnt AS _
     LONG, BYVAL lRowCnt AS LONG) AS LONG
     LOCAL lStyle  AS LONG
     LOCAL tLVC    AS LV_COLUMN
     LOCAL tLVI    AS LV_ITEM
     LOCAL szBuf   AS ASCIIZ * 32
     LOCAL lCol    AS LONG
     LOCAL lRow    AS LONG
     LOCAL hCtl    AS DWORD
     
      CONTROL HANDLE hDlg, lID TO hCtl
     
      lStyle = ListView_GetExtendedListViewStyle(hCtl)
      ListView_SetExtendedListViewStyle hCtl, _
          lStyle OR %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES
     
      'Load column headers.
      tLVC.mask    = %LVCF_FMT OR %LVCF_TEXT OR %LVCF_SUBITEM
      tLVC.fmt     = %LVCFMT_LEFT
      tLVC.pszText = VARPTR(szBuf)
      FOR lCol = 0 TO lColCnt - 1
          szBuf = "Column" + FORMAT$(lCol)
          tLVC.iOrder = lCol
          ListView_InsertColumn hCtl, lCol, tLVC
      NEXT lCol
     
      'Load sample data.
      FOR lRow = 0 TO lRowCnt - 1
          tLVI.stateMask   = %LVIS_FOCUSED
          tLVI.pszText     = VARPTR(szBuf)
          tLVI.iItem       = lRow
          FOR lCol = 0 TO lColCnt - 1
              szBuf           = "Column" + FORMAT$(lCol) + " Row" + FORMAT$(lRow)
              tLVI.iSubItem   = lCol
              tLVI.lParam     = lRow
              IF lCol = 0 THEN
                  tLVI.mask = %LVIF_TEXT OR %LVIF_PARAM OR %LVIF_STATE
                  ListView_InsertItem hCtl, tLVI
              ELSE
                  tLVI.mask = %LVIF_TEXT
                  ListView_SetItem hCtl, tLVI
              END IF
          NEXT lCol
      NEXT i
     
      'Auto size columns.
      FOR lCol = 0 TO lColCnt - 1
          ListView_SetColumnWidth hCtl, lCol, %LVSCW_AUTOSIZE
      NEXT lCol
     
    END FUNCTION
    '------------------/
     
    FUNCTION PBMAIN()
     LOCAL hDlg AS Dword 
     
      InitCommonControls
     
      DIALOG NEW 0, "Dialog1", , , 257, 165, %WS_CAPTION Or %WS_SYSMENU, TO hDlg
      CONTROL ADD "SysListView32", hDlg, %IDC_SYSLISTVIEW32_1, " ", 5, 5, 245, 125, _
        %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %WS_TABSTOP _
        OR %LVS_REPORT OR %LVS_SHOWSELALWAYS, %WS_EX_LEFT OR _
        %WS_EX_RIGHTSCROLLBAR
      CONTROL ADD BUTTON, hDlg, %BTN_BUTTON1, "Button1", 100, 140, 50, 15
     
      SampleListView hDlg, %IDC_SYSLISTVIEW32_1, 5, 30
     
      DIALOG SHOW MODAL hDlg, CALL MainProc
     
    END FUNCTION
    '------------------/
    Last edited by Dave Biggs; 20 Sep 2008, 10:19 AM. Reason: Moved PBMain to end of code - no declares required < PBWin90
    Rgds, Dave

    Comment


    • #3
      Thanks Dave, that is actually quite a bit simpler for me to understand.

      FYI:
      I did have to declare the SampleListView function to compile, but besides that it worked great.

      Comment


      • #4
        OK I admit I don't know what I'm doing.
        What I'm trying to do is load data from an external file and display it in a LV.
        That works.
        Depending on the "status" field, the LV row should be a different color.
        That doesn't work.

        Code:
        #PBFORMS CREATED V1.51
        
        #COMPILE EXE
        #DIM ALL
        
        GLOBAL mainDlg AS DWORD
        GLOBAL mainLV AS DWORD
        GLOBAL paused AS LONG
        GLOBAL c AS LONG
        GLOBAL cRow AS LONG
        
        ' used when reading schedule file
          TYPE schType
            dvSchedule AS STRING * 15
            dvNumber AS LONG
            dvYardsOrdered AS SINGLE
            dvMixDesign AS STRING * 6
            dvAdditives AS STRING * 20
            dvCustomerID AS STRING * 6
            dvDirections AS STRING * 160
            dvStatus AS STRING * 10
            dvCheck AS STRING * 1
          END TYPE
        
          TYPE schSortType
            dvSchedule AS STRING * 15
            dvStatus AS STRING * 10
            dvCheck AS STRING * 1
            dvNumber AS LONG
            dvYardsOrdered AS SINGLE
            dvMixDesign AS STRING * 6
            dvAdditives AS STRING * 20
            dvCustomerID AS STRING * 6
            dvDirections AS STRING * 160
          END TYPE
        
        ' used to read mixtrack datapath
          TYPE localControlType
            dataPath AS STRING * 50
            lptPort1 AS STRING * 5
            uwPort1 AS INTEGER
            lptPort2 AS STRING * 5
            uwPort2 AS INTEGER
          END TYPE
        
        '------------------------------------------------------------------------------
        '   ** Includes **
        '------------------------------------------------------------------------------
        #PBFORMS BEGIN INCLUDES
        %USEMACROS = 1
        #IF NOT %DEF(%WINAPI)
            #INCLUDE "WIN32API.INC"
        #ENDIF
        #IF NOT %DEF(%COMMCTRL_INC)
            #INCLUDE "COMMCTRL.INC"
        #ENDIF
        #INCLUDE "PBForms.INC"
        #PBFORMS END INCLUDES
        '------------------------------------------------------------------------------
        
        '------------------------------------------------------------------------------
        '   ** Constants **
        '------------------------------------------------------------------------------
        #PBFORMS BEGIN CONSTANTS
        %IDD_DIALOG1  =  101
        %lv_schedules = 1001
        %ID_TIMER     = 1002
        %cmd_pause    = 1003
        
        
        #PBFORMS END CONSTANTS
        
        %purple= 8388736
        '------------------------------------------------------------------------------
        
        '------------------------------------------------------------------------------
        '   ** Declarations **
        '------------------------------------------------------------------------------
        DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
        DECLARE FUNCTION SampleListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL _
            lColCnt AS LONG, BYVAL lRowCnt AS LONG) AS LONG
        DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        #PBFORMS DECLARATIONS
        '------------------------------------------------------------------------------
        ' my declarartions
        DECLARE FUNCTION clearLV() AS LONG
        DECLARE FUNCTION populateListView(colData()AS ASCIIZ * 255) AS LONG
        DECLARE FUNCTION AddListViewItem(BYVAL lItemNdx AS LONG, BYVAL lSubItem AS LONG, _
                 sItemText AS ASCIIZ, BYVAL lUniqKey AS LONG) AS LONG
        DECLARE FUNCTION LV_ReadItem( BYVAL lngIndex AS LONG, BYVAL lngColumn AS LONG ) AS STRING
        DECLARE SUB ListView_GetItemText( BYVAL hWndLV AS DWORD, BYVAL i AS LONG, _
                    BYVAL iSubItem AS LONG, pszText AS ASCIIZ, BYVAL cchTextMax AS LONG )
        DECLARE FUNCTION createListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL lColCnt _
            AS LONG, BYVAL lRowCnt AS LONG) AS LONG
        DECLARE FUNCTION loadData() AS LONG
        DECLARE FUNCTION mtPath() AS STRING
        DECLARE FUNCTION Exists(BYVAL LostSheep AS STRING) AS LONG
        DECLARE FUNCTION whiteRed() AS LONG
        DECLARE FUNCTION blackWhite() AS LONG
        DECLARE FUNCTION blackYellow() AS LONG
        
        '------------------------------------------------------------------------------
        '   ** Main Application Entry Point **
        '------------------------------------------------------------------------------
        FUNCTION PBMAIN()
        
            paused=%false
        
            PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
                %ICC_INTERNET_CLASSES)
        
        
            ShowDIALOG1 %HWND_DESKTOP
        
        END FUNCTION
        '------------------------------------------------------------------------------
        
        '------------------------------------------------------------------------------
        '   ** CallBacks **
        '------------------------------------------------------------------------------
        CALLBACK FUNCTION ShowDIALOG1Proc()
             LOCAL lpNmh AS NMHDR PTR
             LOCAL lpLvNm AS NM_LISTVIEW PTR
             LOCAL lpLvCd AS NMLVCUSTOMDRAW PTR
             LOCAL bgcolor AS LONG
             LOCAL fgcolor AS LONG
        
             SELECT CASE AS LONG CBMSG
                CASE %WM_INITDIALOG
                    ' Initialization handler
        
                 ' set up a timer - the screen is always updating
                 SetTimer CBHNDL, %ID_TIMER, 1& * 10000&, BYVAL %NULL
        
                 CASE %WM_TIMER
                     ' update the timer label with the current time
                     IF paused=%false THEN
                         clearLV()
                         loadData()
                     END IF
        
                 CASE %WM_DESTROY
                     ' we should never get here unless it's OK to exit
                     ' kill the timer
                     KillTimer  CBHNDL, %ID_TIMER
        
                CASE %WM_NCACTIVATE
                    STATIC hWndSaveFocus AS DWORD
                    IF ISFALSE CBWPARAM THEN
                        ' Save control focus
                        hWndSaveFocus = GetFocus()
                    ELSEIF hWndSaveFocus THEN
                        ' Restore control focus
                        SetFocus(hWndSaveFocus)
                        hWndSaveFocus = 0
                    END IF
        
                CASE %WM_COMMAND
                    ' Process control notifications
                    SELECT CASE AS LONG CBCTL
                        CASE %lv_schedules
        
                        CASE %cmd_pause
                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
        
                                    IF paused=%false THEN
                                        paused=%true
                                        CONTROL SET TEXT mainDlg, %cmd_pause, "* Paused *"
                                    ELSE
                                        paused=%false
                                        CONTROL SET TEXT mainDlg, %cmd_pause, "Pause"
                                    END IF
        
                                END IF
        
                    END SELECT
        
                    CASE %WM_NOTIFY
                       SELECT CASE c
                           CASE 1  ' black on yellow
                                fgColor=%BLACK
                                bgColor=%YELLOW
                           CASE 2  ' black on white
                                fgColor=%BLACK
                                bgColor=%WHITE
                           CASE 3  ' white on red
                                fgColor=%WHITE
                                bgColor=%RED
                           CASE ELSE
                                fgColor=%WHITE
                                bgColor=%purple
                       END SELECT
                      lpNmh = CBLPARAM
                       SELECT CASE @lpNmh.idFrom
                         CASE %lv_schedules
                           lpLvNm = CBLPARAM
                           SELECT CASE @LpLvNm.hdr.code
                             CASE %NM_CUSTOMDRAW
                               lpLvCd = CBLPARAM
                               SELECT CASE @lplvcd.nmcd.dwDrawStage
                                 CASE %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
                                   FUNCTION = %CDRF_NOTIFYSUBITEMDRAW
                                 CASE %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM
                                   'IF testColour = %TRUE THEN
                                     IF @lpLvCd.nmcd.dwItemSpec = CRow THEN   ' CRow = Row to be coloured
                                        @lpLvCd.clrTextBk = bgColor
                                        @lpLvCd.clrText = fgColor
                                     END IF
                                  ' ELSE
                                  '    @lpLvCd.clrTextBk = bgColor
                                   '   @lpLvCd.clrText = fgColor
                                   'END IF
                                  FUNCTION = %CDRF_NEWFONT
                               END SELECT
                           END SELECT
                       END SELECT
        
            END SELECT
        END FUNCTION
        '------------------------------------------------------------------------------
        
        
        '------------------------------------------------------------------------------
        '   ** Dialogs **
        '------------------------------------------------------------------------------
        FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
            LOCAL lRslt AS LONG
            LOCAL value AS LONG
        
        #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
            LOCAL hDlg  AS DWORD
        
            DIALOG NEW hParent, "mSchedule v1.2", 81, 131, 688, 455, %WS_POPUP OR _
                %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR _
                %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR , TO hDlg
        
                ' set global handle
                mainDlg = hDlg
        
            CONTROL ADD BUTTON, hDlg, %cmd_pause, "Pause", 630, 10, 40, 15
        
            CONTROL ADD "SysListView32", hDlg, %lv_schedules, _
                "SysListView32_1", 10, 30, 660, 415, %WS_CHILD OR %WS_VISIBLE OR _
                %WS_TABSTOP OR %LVS_REPORT OR %LVS_SHOWSELALWAYS, %WS_EX_LEFT OR _
                %WS_EX_CLIENTEDGE OR %WS_EX_RIGHTSCROLLBAR
        #PBFORMS END DIALOG
        
            ' format listview
            createListView hDlg, %lv_schedules , 6, 30
            loadData()
            DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
        
        
        #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
        #PBFORMS END CLEANUP
        
            FUNCTION = lRslt
        END FUNCTION
        '------------------------------------------------------------------------------
        
        ' -------------------------------------------------------------------------
        ' Function: Add an item to a ListView control
        ' Accepts : lItemNdx - Item index (row number)
        '           lSubItem - Subitem index (column number)
        '           sItemText - Text to place in the item
        '           lUniqKey - ID code of the item
        ' Returns : True on success, False on failure
        ' -------------------------------------------------------------------------
        FUNCTION AddListViewItem(BYVAL lItemNdx AS LONG, BYVAL lSubItem AS LONG, _
                 sItemText AS ASCIIZ, BYVAL lUniqKey AS LONG) AS LONG
        
           LOCAL Lvi AS LV_ITEM
           LOCAL value AS LONG
           LOCAL fgColor, bgColor AS LONG
           LOCAL result AS LONG
        
           Lvi.STATE     = 0
           Lvi.statemask = %LVIS_FOCUSED
           Lvi.isubitem  = lSubItem
           Lvi.pszText   = VARPTR(sItemText)
           Lvi.lparam    = lUniqKey
           lvi.iItem     = lItemNdx
        
           IF lSubItem = 0 THEN
              Lvi.mask        = %LVIF_TEXT OR %LVIF_PARAM OR %LVIF_STATE
              Lvi.iItem       = lItemNdx
              AddListViewItem = ListView_InsertItem(mainLV, Lvi)
        
           ELSE
              Lvi.mask        = %LVIF_TEXT
              AddListviewItem = ListView_SetItem(mainLV, Lvi)
        
           END IF
        
        END FUNCTION
        
        ' loads data from data file and loads to listview
        FUNCTION loadData() AS LONG
            DIM schVar AS schtype
            LOCAL fNumber AS LONG
            LOCAL fName AS STRING
            LOCAL nor AS LONG
            LOCAL i AS LONG
            DIM colData(8) AS ASCIIZ * 255
            DIM sortData(1) AS schSortType
        
            fname=mtpath+"sche.mt"   ' scheduler data
        
            fNumber=FREEFILE
        
            OPEN fName FOR RANDOM AS #fNumber LEN=SIZEOF(schVar)
            nor=LOF(fNumber)/LEN(schVar)
        
            IF nor=0 THEN EXIT FUNCTION
        
            REDIM sortData(nor)
            FOR i = 1 TO nor
                GET #fNumber,i,schVar
                sortData(i).dvSchedule=schVar.dvSchedule
                sortData(i).dvNumber=schVar.dvNumber
                sortData(i).dvYardsOrdered=schVar.dvYardsOrdered
                sortData(i).dvMixDesign=schVar.dvMixDesign
                sortData(i).dvAdditives=schVar.dvAdditives
                sortData(i).dvCustomerID=schVar.dvCustomerID
                sortData(i).dvDirections=schVar.dvDirections
                sortData(i).dvStatus=schVar.dvStatus
                sortData(i).dvCheck=schVar.dvCheck
            NEXT
        
            CLOSE #fNumber
        
            ARRAY SORT sortData()
        
            FOR i = 1 TO nor
                colData(0)=TRIM$(sortData(i).dvSchedule)
                colData(1)=TRIM$(sortData(i).dvStatus)
                colData(2)=TRIM$(sortData(i).dvCheck)
                colData(3)=TRIM$(STR$(sortData(i).dvNumber))
                colData(4)=TRIM$(STR$(sortData(i).dvYardsOrdered))
                coldata(5)=TRIM$(sortData(i).dvMixDesign)
                colData(6)=TRIM$(sortData(i).dvAdditives)
                colData(7)=TRIM$(sortData(i).dvCustomerID)
                colData(8)=TRIM$(sortData(i).dvDirections)
                populateListView(colData())
            NEXT
        
        END FUNCTION
        
        ' add rows of items to listView
        FUNCTION populateListView(colData()AS ASCIIZ * 255) AS LONG
            LOCAL lItemNdx AS LONG          'Item index (row number)
            LOCAL lSubItem AS LONG          'Subitem index (column number)
            LOCAL sItemText AS ASCIIZ * 255 'Text to place in the item
            LOCAL lUniqKey  AS LONG         'ID code of the item
            LOCAL i AS LONG
            LOCAL temp AS STRING
            LOCAL c AS LONG
        
            lItemNDX=ListView_GetItemCount(mainLV)
            cRow=lItemNdx
        
            ' set colors
                temp=LCASE$(TRIM$(colData(1)))
        
                SELECT CASE temp
                    CASE "conf"
                        ' yellow
                        c=1
                    CASE "w/c"
                        ' white
                        c=2
                    CASE "done"
                        ' red
                        c=3
                    CASE ELSE
                        c=2
                END SELECT
        
            FOR i = 0 TO 8
                lSubItem=i
                sItemText=colData(i)
                AddListViewItem(BYVAL lItemNdx, BYVAL lSubItem, sItemText, BYVAL lUniqKey)
            NEXT
        
        END FUNCTION
        
        ' clears list view
        FUNCTION clearLV() AS LONG
            sendMessage mainLV, %LVM_DELETEALLITEMS, 0, 0
        END FUNCTION
        
        ' create list view
        FUNCTION createListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL lColCnt _
            AS LONG, BYVAL lRowCnt AS LONG) AS LONG
            LOCAL lCol   AS LONG
            LOCAL lRow   AS LONG
            LOCAL lvHdl     AS DWORD
            LOCAL tLVC   AS LV_COLUMN
            LOCAL tLVI   AS LV_ITEM
            LOCAL szBuf  AS ASCIIZ * 32
            LOCAL lStyle AS LONG
            LOCAL colWidth AS LONG
        
            CONTROL HANDLE hDlg, lID TO lvHdl
        
            lStyle = ListView_GetExtendedListViewStyle(lvHdl)
            ListView_SetExtendedListViewStyle(lvHdl , lStyle OR %LVS_EX_FULLROWSELECT _
                OR %LVS_EX_GRIDLINES)
        
            ' Load column headers.
            tLVC.mask    = %LVCF_FMT OR %LVCF_TEXT OR %LVCF_SUBITEM
            tLVC.fmt     = %LVCFMT_LEFT
            tLVC.pszText = VARPTR(szBuf)
        
            ' setup column headers
        
                colWidth=90
                szBuf       = "Time"
                lCol=0
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                colWidth=90
                szBuf       = "Status"
                lCol=1
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                colWidth=30
                szBuf       = "chk"
                lCol=2
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                colWidth=90
                szBuf       = "Ticket Number"
                lCol=3
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                colWidth=90
                szBuf       = "Yards Ordered"
                lCol=4
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                colWidth=90
                szBuf       = "Mix Design"
                lCol=5
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                colWidth=60
                szBuf       = "Additives"
                lCol=6
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                colWidth=90
                szBuf       = "Customer ID"
                lCol=7
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                colWidth=475
                szBuf       = "Directions"
                lCol=8
                tLVC.iOrder = lCol
                ListView_InsertColumn(lvHdl  , lCol, tLVC)
                ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
        
                mainLV=lvHdl  ' store global var for lv handle
        
        END FUNCTION
        
        ' return path to mixtrack data files
        FUNCTION mtPath() AS STRING
          LOCAL fNumber AS LONG
          LOCAL fName AS STRING
          LOCAL lcVar AS localControlType
        
          function=""
          exit function
        
        ' for compatability later
        
          fNumber = FREEFILE
          fName = "dp.mt"
        
          IF exists(fName) THEN
            OPEN fName FOR RANDOM AS #fNumber
            GET #fNumber, 1, lcVar
            CLOSE #fNumber
            FUNCTION = TRIM$(lcVar.dataPath)
          ELSE
            FUNCTION = ""
          END IF
        END FUNCTION
        
        ' check for file existence
        FUNCTION Exists(BYVAL LostSheep AS STRING) AS LONG
          FUNCTION = (LEN(DIR$(LostSHeep)) > 0)
        END FUNCTION
        Attached Files

        Comment


        • #5
          If the color in which you must paint is based on the data, you have no choice but to either store the data in the control, or retain it somewhere and go get it at painting time.

          You can put that status flag in a hidden column if you like (eg "yes" or "no" depending if this row should be colored or not.

          then at painting time, you read the value of that column for that row and choose your colors accordiningly.

          Normally I would use the lvitem.lparam for this, but I see you are already using that for something else and I didn't want to mess up your use of that field.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            The filed that holds the value determining the row color is already on the listview. It is under the "status" column. It will either be w/c, done, conf, or a blank field.
            What I've done is save a value in lParam
            Code:
            FUNCTION AddListViewItem(BYVAL lItemNdx AS LONG, BYVAL lSubItem AS LONG, _
                     sItemText AS ASCIIZ, BYVAL lUniqKey AS LONG) AS LONG
            
               LOCAL Lvi AS LV_ITEM
               LOCAL value AS LONG
            
               Lvi.STATE     = 0
               Lvi.statemask = %LVIS_FOCUSED
               Lvi.isubitem  = lSubItem
               Lvi.pszText   = VARPTR(sItemText)
               Lvi.lparam    = lUniqKey     ' this is 1,2,3, or 4 which denotes a color combination
               lvi.iItem     = lItemNdx
            
               IF lSubItem = 0 THEN
                  Lvi.mask        = %LVIF_TEXT OR %LVIF_PARAM OR %LVIF_STATE
                  Lvi.iItem       = lItemNdx
                  AddListViewItem = ListView_InsertItem(mainLV, Lvi)
            
               ELSE
                  Lvi.mask        = %LVIF_TEXT
                  AddListviewItem = ListView_SetItem(mainLV, Lvi)
            
               END IF
            
            END FUNCTION
            I don't think I want to use %wm_notify to continually repaint. I only want to do it one time, when the data is loaded.
            Attached Files
            Last edited by Shawn Anderson; 19 Sep 2008, 03:46 PM. Reason: typo

            Comment


            • #7
              one other question:

              Is there no way to specify fore/background colors using lv_item when inserting an item into the listview? That is what I really want to do.

              Comment


              • #8
                unbelievably (thanks to yours and MSDN's help) I figured this out.

                my final code:
                Code:
                #PBFORMS CREATED V1.51
                
                #COMPILE EXE
                #DIM ALL
                
                GLOBAL mainDlg AS DWORD
                GLOBAL mainLV AS DWORD
                GLOBAL paused AS LONG
                
                ' used when reading schedule file
                  TYPE schType
                    dvSchedule AS STRING * 15
                    dvNumber AS LONG
                    dvYardsOrdered AS SINGLE
                    dvMixDesign AS STRING * 6
                    dvAdditives AS STRING * 20
                    dvCustomerID AS STRING * 6
                    dvDirections AS STRING * 160
                    dvStatus AS STRING * 10
                    dvCheck AS STRING * 1
                  END TYPE
                
                  TYPE schSortType
                    dvSchedule AS STRING * 15
                    dvStatus AS STRING * 10
                    dvCheck AS STRING * 1
                    dvNumber AS LONG
                    dvYardsOrdered AS SINGLE
                    dvMixDesign AS STRING * 6
                    dvAdditives AS STRING * 20
                    dvCustomerID AS STRING * 6
                    dvDirections AS STRING * 160
                  END TYPE
                
                ' used to read mixtrack datapath
                  TYPE localControlType
                    dataPath AS STRING * 50
                    lptPort1 AS STRING * 5
                    uwPort1 AS INTEGER
                    lptPort2 AS STRING * 5
                    uwPort2 AS INTEGER
                  END TYPE
                
                '------------------------------------------------------------------------------
                '   ** Includes **
                '------------------------------------------------------------------------------
                #PBFORMS BEGIN INCLUDES
                %USEMACROS = 1
                #IF NOT %DEF(%WINAPI)
                    #INCLUDE "WIN32API.INC"
                #ENDIF
                #IF NOT %DEF(%COMMCTRL_INC)
                    #INCLUDE "COMMCTRL.INC"
                #ENDIF
                #INCLUDE "PBForms.INC"
                #PBFORMS END INCLUDES
                '------------------------------------------------------------------------------
                
                '------------------------------------------------------------------------------
                '   ** Constants **
                '------------------------------------------------------------------------------
                #PBFORMS BEGIN CONSTANTS
                %IDD_DIALOG1  =  101
                %lv_schedules = 1001
                %ID_TIMER     = 1002
                %cmd_pause    = 1003
                
                #PBFORMS END CONSTANTS
                
                %purple= 8388736
                '------------------------------------------------------------------------------
                
                '------------------------------------------------------------------------------
                '   ** Declarations **
                '------------------------------------------------------------------------------
                DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                DECLARE FUNCTION SampleListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL _
                    lColCnt AS LONG, BYVAL lRowCnt AS LONG) AS LONG
                DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                #PBFORMS DECLARATIONS
                '------------------------------------------------------------------------------
                ' my declarartions
                DECLARE FUNCTION clearLV() AS LONG
                DECLARE FUNCTION populateListView(colData()AS ASCIIZ * 255) AS LONG
                DECLARE FUNCTION AddListViewItem(BYVAL lItemNdx AS LONG, BYVAL lSubItem AS LONG, _
                         sItemText AS ASCIIZ, BYVAL lUniqKey AS LONG) AS LONG
                DECLARE FUNCTION LV_ReadItem( BYVAL lngIndex AS LONG, BYVAL lngColumn AS LONG ) AS STRING
                DECLARE SUB ListView_GetItemText( BYVAL hWndLV AS DWORD, BYVAL i AS LONG, _
                            BYVAL iSubItem AS LONG, pszText AS ASCIIZ, BYVAL cchTextMax AS LONG )
                DECLARE FUNCTION createListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL lColCnt _
                    AS LONG, BYVAL lRowCnt AS LONG) AS LONG
                DECLARE FUNCTION loadData() AS LONG
                DECLARE FUNCTION mtPath() AS STRING
                DECLARE FUNCTION Exists(BYVAL LostSheep AS STRING) AS LONG
                DECLARE FUNCTION whiteRed() AS LONG
                DECLARE FUNCTION blackWhite() AS LONG
                DECLARE FUNCTION blackYellow() AS LONG
                
                '------------------------------------------------------------------------------
                '   ** Main Application Entry Point **
                '------------------------------------------------------------------------------
                FUNCTION PBMAIN()
                    paused=%false
                
                    PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
                        %ICC_INTERNET_CLASSES)
                
                    ShowDIALOG1 %HWND_DESKTOP
                
                END FUNCTION
                '------------------------------------------------------------------------------
                
                '------------------------------------------------------------------------------
                '   ** CallBacks **
                '------------------------------------------------------------------------------
                CALLBACK FUNCTION ShowDIALOG1Proc()
                     LOCAL lpNmh AS NMHDR PTR              ' pointer listview notfication message
                     LOCAL lpLvNm AS NM_LISTVIEW PTR       ' pointer listview notification message
                     LOCAL lpLvCd AS NMLVCUSTOMDRAW PTR    ' pointer listview custom draw
                     LOCAL bgcolor AS LONG
                     LOCAL fgcolor AS LONG
                
                     SELECT CASE AS LONG CBMSG
                        CASE %WM_INITDIALOG
                         ' Initialization handler
                
                         ' set up a timer - the screen is always updating
                         SetTimer CBHNDL, %ID_TIMER, 1& * 10000&, BYVAL %NULL
                
                         CASE %WM_TIMER
                             ' update the timer label with the current time
                             IF paused=%false THEN
                                 clearLV()
                                 loadData()
                             END IF
                
                         CASE %WM_DESTROY
                             ' we should never get here unless it's OK to exit
                             ' kill the timer
                             KillTimer  CBHNDL, %ID_TIMER
                
                        CASE %WM_NCACTIVATE
                            STATIC hWndSaveFocus AS DWORD
                            IF ISFALSE CBWPARAM THEN
                                ' Save control focus
                                hWndSaveFocus = GetFocus()
                            ELSEIF hWndSaveFocus THEN
                                ' Restore control focus
                                SetFocus(hWndSaveFocus)
                                hWndSaveFocus = 0
                            END IF
                
                        CASE %WM_COMMAND
                            ' Process control notifications
                            SELECT CASE AS LONG CBCTL
                                CASE %lv_schedules
                
                                CASE %cmd_pause
                                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                            IF paused=%false THEN
                                                paused=%true
                                                CONTROL SET TEXT mainDlg, %cmd_pause, "* Paused *"
                                            ELSE
                                                paused=%false
                                                CONTROL SET TEXT mainDlg, %cmd_pause, "Pause"
                                            END IF
                
                                        END IF
                            END SELECT
                
                         CASE %WM_NOTIFY
                             lpNmh = CBLPARAM
                               SELECT CASE @lpNmh.idFrom
                                 CASE %lv_schedules
                                   lpLvNm = CBLPARAM
                                   SELECT CASE @LpLvNm.hdr.code
                                     CASE %NM_CUSTOMDRAW
                                       lpLvCd = CBLPARAM
                                       SELECT CASE @lplvcd.nmcd.dwDrawStage
                                         CASE %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
                                           FUNCTION = %CDRF_NOTIFYSUBITEMDRAW
                                         CASE %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM
                
                                             SELECT CASE @lpLvCd.nmcd.lItemlParam
                                                CASE 1
                                                    fgColor=%BLACK
                                                    bgColor=%YELLOW
                                                CASE 2
                                                    fgColor=%BLACK
                                                    bgColor=%WHITE
                                                CASE 3
                                                    fgColor=%WHITE
                                                    bgColor=%RED
                                                CASE ELSE
                                                    fgColor=%WHITE
                                                    bgColor=%purple
                                             END SELECT
                
                                             @lpLvCd.clrTextBk = bgColor
                                             @lpLvCd.clrText = fgColor
                
                                          FUNCTION = %CDRF_NEWFONT
                                       END SELECT
                                   END SELECT
                               END SELECT
                
                    END SELECT
                END FUNCTION
                '------------------------------------------------------------------------------
                
                
                '------------------------------------------------------------------------------
                '   ** Dialogs **
                '------------------------------------------------------------------------------
                FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                    LOCAL lRslt AS LONG
                    LOCAL value AS LONG
                
                #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
                    LOCAL hDlg  AS DWORD
                
                    DIALOG NEW hParent, "mSchedule v1.3", 81, 131, 688, 455, %WS_POPUP OR _
                        %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR _
                        %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                        %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                        OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR , TO hDlg
                
                        ' set global handle
                        mainDlg = hDlg
                
                    CONTROL ADD BUTTON, hDlg, %cmd_pause, "Pause", 630, 10, 40, 15
                
                    CONTROL ADD "SysListView32", hDlg, %lv_schedules, _
                        "SysListView32_1", 10, 30, 660, 415, %WS_CHILD OR %WS_VISIBLE OR _
                        %WS_TABSTOP OR %LVS_REPORT OR %LVS_SHOWSELALWAYS, %WS_EX_LEFT OR _
                        %WS_EX_CLIENTEDGE OR %WS_EX_RIGHTSCROLLBAR
                #PBFORMS END DIALOG
                
                    ' format listview
                    createListView hDlg, %lv_schedules , 6, 30
                    loadData()
                    DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                
                
                #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
                #PBFORMS END CLEANUP
                
                    FUNCTION = lRslt
                END FUNCTION
                '------------------------------------------------------------------------------
                
                ' -------------------------------------------------------------------------
                ' Function: Add an item to a ListView control
                ' Accepts : lItemNdx - Item index (row number)
                '           lSubItem - Subitem index (column number)
                '           sItemText - Text to place in the item
                '           lUniqKey - ID code of the item
                ' Returns : True on success, False on failure
                ' -------------------------------------------------------------------------
                FUNCTION AddListViewItem(BYVAL lItemNdx AS LONG, BYVAL lSubItem AS LONG, _
                         sItemText AS ASCIIZ, BYVAL lUniqKey AS LONG) AS LONG
                
                   LOCAL Lvi AS LV_ITEM
                   LOCAL value AS LONG
                
                   Lvi.STATE     = 0
                   Lvi.statemask = %LVIS_FOCUSED
                   Lvi.isubitem  = lSubItem               ' column
                   Lvi.pszText   = VARPTR(sItemText)      ' text
                   Lvi.lparam    = lUniqKey               ' 1,2,3 or 4 (color combination)
                   lvi.iItem     = lItemNdx               ' row
                
                   IF lSubItem = 0 THEN
                      Lvi.mask        = %LVIF_TEXT OR %LVIF_PARAM OR %LVIF_STATE
                      Lvi.iItem       = lItemNdx
                      AddListViewItem = ListView_InsertItem(mainLV, Lvi)
                
                   ELSE
                      Lvi.mask        = %LVIF_TEXT
                      AddListviewItem = ListView_SetItem(mainLV, Lvi)
                
                   END IF
                
                END FUNCTION
                
                ' loads data from data file and loads to listview
                FUNCTION loadData() AS LONG
                    DIM schVar AS schtype
                    LOCAL fNumber AS LONG
                    LOCAL fName AS STRING
                    LOCAL nor AS LONG
                    LOCAL i AS LONG
                    DIM colData(8) AS ASCIIZ * 255
                    DIM blankData(8) AS ASCIIZ * 255
                    DIM sortData(1) AS schSortType
                    LOCAL tempSCH AS STRING
                
                    fname=mtpath+"sche.mt"   ' scheduler data
                    fNumber=FREEFILE
                
                    OPEN fName FOR RANDOM AS #fNumber LEN=SIZEOF(schVar)
                    nor=LOF(fNumber)/LEN(schVar)
                
                    IF nor=0 THEN EXIT FUNCTION
                
                    ' create empty
                    FOR i = 0 TO 8
                        blankData(i)=""
                    NEXT
                
                    REDIM sortData(nor)
                    FOR i = 1 TO nor
                        GET #fNumber,i,schVar
                        sortData(i).dvSchedule=schVar.dvSchedule
                        sortData(i).dvNumber=schVar.dvNumber
                        sortData(i).dvYardsOrdered=schVar.dvYardsOrdered
                        sortData(i).dvMixDesign=schVar.dvMixDesign
                        sortData(i).dvAdditives=schVar.dvAdditives
                        sortData(i).dvCustomerID=schVar.dvCustomerID
                        sortData(i).dvDirections=schVar.dvDirections
                        sortData(i).dvStatus=schVar.dvStatus
                        sortData(i).dvCheck=schVar.dvCheck
                    NEXT
                
                    CLOSE #fNumber
                
                    ARRAY SORT sortData()
                
                    FOR i = 1 TO nor
                
                        IF TRIM$(sortData(i).dvSchedule) <> tempSch AND i <> 1 THEN
                        ' insert a blank line after alike time groups
                            populateListView(blankData())
                        END IF
                
                        colData(0)=TRIM$(sortData(i).dvSchedule)
                        colData(1)=TRIM$(sortData(i).dvStatus)
                        colData(2)=TRIM$(sortData(i).dvCheck)
                        colData(3)=TRIM$(STR$(sortData(i).dvNumber))
                        colData(4)=TRIM$(STR$(sortData(i).dvYardsOrdered))
                        coldata(5)=TRIM$(sortData(i).dvMixDesign)
                        colData(6)=TRIM$(sortData(i).dvAdditives)
                        colData(7)=TRIM$(sortData(i).dvCustomerID)
                        colData(8)=TRIM$(sortData(i).dvDirections)
                        populateListView(colData())
                
                        tempSch=TRIM$(sortData(i).dvSchedule)
                    NEXT
                
                END FUNCTION
                
                ' add rows of items to listView
                FUNCTION populateListView(colData()AS ASCIIZ * 255) AS LONG
                    LOCAL lItemNdx AS LONG          'Item index (row number)
                    LOCAL lSubItem AS LONG          'Subitem index (column number)
                    LOCAL sItemText AS ASCIIZ * 255 'Text to place in the item
                    LOCAL lUniqKey  AS LONG         'ID code of the item
                    LOCAL i AS LONG
                    LOCAL temp AS STRING
                
                    lItemNDX=ListView_GetItemCount(mainLV)
                
                    ' set colors
                        temp=LCASE$(TRIM$(colData(1)))
                
                        SELECT CASE temp
                            CASE "conf"
                                lUniqKey=1    ' yellow
                            CASE "w/c"
                                lUniqKey=2    ' white
                            CASE "done"
                                lUniqKey=3    ' red
                            CASE ELSE
                                lUniqKey=2    ' white
                        END SELECT
                
                    FOR i = 0 TO 8
                        lSubItem=i
                        sItemText=colData(i)
                        AddListViewItem(BYVAL lItemNdx, BYVAL lSubItem, sItemText, BYVAL lUniqKey )
                    NEXT
                
                END FUNCTION
                
                ' clears list view
                FUNCTION clearLV() AS LONG
                    LOCAL rows AS LONG
                    LOCAL i AS LONG
                    sendMessage mainLV, %LVM_DELETEALLITEMS, 0, 0
                
                '    delete one at a time
                '    rows=ListView_GetItemCount(mainLV)
                '    FOR i = 0 TO (rows-1)
                '      listview_deleteItem (mainLV, 0)
                '    NEXT
                
                END FUNCTION
                
                ' create list view
                FUNCTION createListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL lColCnt _
                    AS LONG, BYVAL lRowCnt AS LONG) AS LONG
                    LOCAL lCol   AS LONG
                    LOCAL lRow   AS LONG
                    LOCAL lvHdl     AS DWORD
                    LOCAL tLVC   AS LV_COLUMN
                    LOCAL tLVI   AS LV_ITEM
                    LOCAL szBuf  AS ASCIIZ * 32
                    LOCAL lStyle AS LONG
                    LOCAL colWidth AS LONG
                
                    CONTROL HANDLE hDlg, lID TO lvHdl
                
                    lStyle = ListView_GetExtendedListViewStyle(lvHdl)
                    ListView_SetExtendedListViewStyle(lvHdl , lStyle OR %LVS_EX_FULLROWSELECT _
                        OR %LVS_EX_GRIDLINES)
                
                    ' Load column headers.
                    tLVC.mask    = %LVCF_FMT OR %LVCF_TEXT OR %LVCF_SUBITEM
                    tLVC.fmt     = %LVCFMT_LEFT
                    tLVC.pszText = VARPTR(szBuf)
                
                    ' setup column headers
                
                        colWidth=90
                        szBuf       = "Time"
                        lCol=0
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        colWidth=90
                        szBuf       = "Status"
                        lCol=1
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        colWidth=30
                        szBuf       = "chk"
                        lCol=2
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        colWidth=90
                        szBuf       = "Ticket Number"
                        lCol=3
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        colWidth=90
                        szBuf       = "Yards Ordered"
                        lCol=4
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        colWidth=90
                        szBuf       = "Mix Design"
                        lCol=5
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        colWidth=60
                        szBuf       = "Additives"
                        lCol=6
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        colWidth=90
                        szBuf       = "Customer ID"
                        lCol=7
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        colWidth=475
                        szBuf       = "Directions"
                        lCol=8
                        tLVC.iOrder = lCol
                        ListView_InsertColumn(lvHdl  , lCol, tLVC)
                        ListView_SetColumnWidth(lvHdl  , lCol, colWidth)
                
                        mainLV=lvHdl  ' store global var for lv handle
                
                END FUNCTION
                
                ' return path to mixtrack data files
                FUNCTION mtPath() AS STRING
                  LOCAL fNumber AS LONG
                  LOCAL fName AS STRING
                  LOCAL lcVar AS localControlType
                
                  fNumber = FREEFILE
                  fName = "dp.mt"
                
                  IF exists(fName) THEN
                    OPEN fName FOR RANDOM AS #fNumber
                    GET #fNumber, 1, lcVar
                    CLOSE #fNumber
                    FUNCTION = TRIM$(lcVar.dataPath)
                  ELSE
                    FUNCTION = ""
                  END IF
                END FUNCTION
                
                ' check for file existence
                FUNCTION Exists(BYVAL LostSheep AS STRING) AS LONG
                  FUNCTION = (LEN(DIR$(LostSHeep)) > 0)
                END FUNCTION
                Last edited by Shawn Anderson; 19 Sep 2008, 09:53 PM.

                Comment


                • #9
                  Hi Shawn,

                  Have you tried adding a WinXP Theme manifest to your application? I was working on a custom draw listview a few weeks ago and adding the manifest caused the drawing to cease working correctly.
                  Paul Squires
                  FireFly Visual Designer (for PowerBASIC Windows 10+)
                  Version 3 now available.
                  http://www.planetsquires.com

                  Comment


                  • #10
                    I don't think I want to use %wm_notify to continually repaint. I only want to do it one time, when the data is loaded.
                    Well, I think painting on WM_NOTFY is exactly what you want to do. I don't think you DON'T want to repaint when...

                    - The user scrolls the screen
                    - The user minimizes then restores
                    - Another window gets dragged over your window and then moves off

                    Don't you want the screen repainted then?

                    Well it is YOUR LUCKY DAY!!

                    The WM_NOTIFY message actually NOTIFIES you when a row MUST be repainted, and ONLY when a row MUST be repainted. (hence the clever name of the message).

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Paul:
                      no.. i wouldn't know how if I wanted to

                      MCM:
                      What will those guys at Microsoft think of next?
                      Seriously though, thanks for explaining that. When I was testing it looked like
                      wm_notify was hitting true more often. Clearly it was me.

                      Comment


                      • #12
                        FYI:
                        I did have to declare the SampleListView function to compile, but besides that it worked great.
                        Oops! Sorry about that - I was using the new compiler that does away with declares and didn't notice.
                        I would have put PBMain() last in the sample if I'd been a bit more on the ball. (That way the (earlier version) compiler would see the function before it was called and not complain).
                        Rgds, Dave

                        Comment


                        • #13
                          Just for style points...

                          If you can use the 'default' painting EXCEPT when the row is 'special' , you can return CDRF_DODEFAULT if the row is not special...
                          Code:
                          SELECT CASE @lplvcd.nmcd.dwDrawStage
                                                   CASE %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
                                                       Listview_getItemText  _
                                                                  @lplvcd.nmcd.dwItemdspec, columnofitnerest, sztext, SIZEOF(sztext) 
                                                       IF szText = "SPECIAL PAINTING REQUIRED"  THEN 
                                                             FUNCTION = CDRF_NOTIFYSUBITEMDRAW 
                                                       ELSE 
                                                            FUCNTION = CDRF_DODEFAULT
                                                       END IF
                          When DODEFAULT is returned in response to the ITEM (row) notification it will eliminate all the SUBITEM (columns) notifications for the row to be painted.

                          I have an example of using the default drawing at ..
                          Listview with Multiple Checkbox Columns Demo 2-20-05

                          Oops, that's the old forum reference. I guess I never updated my list on my laptop which I'm using right now. But it should still be there. That uses defaults at the subitem rather than item level but the principle is the same.

                          You might also check this one (also old forum ref)... I might be using the default when the row is not green:
                          Simple Report Viewer Using Listview Control November 23, 2002; updated 5/30/05 to 'greenbar' file viewer


                          MCM
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment

                          Working...
                          X