Announcement

Collapse
No announcement yet.

Listview advantages?

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

  • Listview advantages?

    Never used Listview until today and have been very impressed.
    Can the control be as fast as using a grid? Can it be used in a virtual mode?
    Is the control a good alternative to using a grid?
    Is the control good for displaying data aligned in columns?
    Is the control good for sorting data?
    Can the listview display grid lines?
    Where is the best documention on using Listview?
    Thank you.
    How long is an idea? Write it down.

  • #2
    Can the control be as fast as using a grid? Yes
    Can it be used in a virtual mode? Yes
    Is the control a good alternative to using a grid? Yes
    Is the control good for displaying data aligned in columns? Yes
    Is the control good for sorting data? Yes
    Can the listview display grid lines? Yes
    Where is the best documention on using Listview? Around here or search poffs
    "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

    Comment


    • #3
      Thank you!
      Found a lot of information.
      Should have used this before.

      Not sure why I'm not getting emails when someone responds to this thread? Have Instant email notifcation is enabled.
      Duh, turned off popwiz while testing the new port monitor.

      Already have a good looking port monitor using the Listview.
      1) Now trying to figure out how to get scrollbars?
      2) How to sort numerically instead of by string the port number column?
      Last edited by Mike Doty; 21 Nov 2007, 01:00 PM.
      How long is an idea? Write it down.

      Comment


      • #4
        Mike,

        About the only thing I don't like about the listview control, is its inability to edit anything but the first column. I've seen some ways around this, but basically, the control is useful mainly for display and not entry.

        What I usually do however, is create a series of text boxes beneath the LV control that match up with the columns. Then when a row is selected, I populate these edit boxes. Any changes the user wants to make are done in the edit box and then the LV is updated. There is a way to set a long value for each row which I sometimes use as a flag to indicate changed data that needs to be saved. Also, if you set the last column with a length of -1, the column is essentially hidden (there is an easy way to prevent the column from being resized if you need) making it an excellent way to store database keys for fast access later on.

        The LV is a very functional control. I can't say that I've written a program in the past few years without at least a few of them.
        Software makes Hardware Happen

        Comment


        • #5
          Thanks for the info!
          I've been using Flexcell http://www.grid2000.com but it requires COM.
          My port monitor is under 10K! The one I've used NetMon was 509K.
          How long is an idea? Write it down.

          Comment


          • #6
            Originally posted by Joe Byrne View Post
            Mike,

            About the only thing I don't ...create a series of text boxes beneath the LV control that match up with the columns.
            I've been thinking about that, but how do you handle resizing a column? do you recreate the text boxen when the resize event occurs if so, how?

            Comment


            • #7
              >do you recreate the text box

              You could just resize the text box; there's no need to recreate it.
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Originally posted by Chris Holbrook View Post
                I've been thinking about that, but how do you handle resizing a column? do you recreate the text boxen when the resize event occurs if so, how?
                Chris,
                That is an issue. At this time, I haven't really dealt with it. My forms are, for the most part, fixed. I use Lance Edmound's Resize32 utility to allow dynamic resizing of my forms, and it works great, except for the text box alignment with the LV columns. So what I do is exclude the LV from resizing. Most of the time, the form still looks pretty good, but if the user drags the width of the columns, things get out of whack.

                If/when it becomes an issue, I'll have to look into synchronizing the size of the text boxes with the column widths. I'm pretty sure its not all that difficult, but until I hear some complaints I'll just back-burner it for now.
                Software makes Hardware Happen

                Comment


                • #9
                  Joe,

                  I've approached th same thing by popping up a dialog to edit the row "exploded" which is a bit crude but reliable.

                  Column size can (they tell me) be got by

                  lResult = SendMessage( // returns LRESULT in lResult
                  (HWND) hWndControl, // handle to destination control
                  (UINT) LVM_GETCOLUMNWIDTH, // message ID
                  (WPARAM) wParam, // = (WPARAM) (int) iCol;
                  (LPARAM) lParam // = 0; not used, must be zero );
                  Any idea what message results from resizing?

                  Comment


                  • #10
                    >Any idea what message results from resizing [columns of listview]?

                    You get WM_NOTIFY/HDN_ENDTRACK with nmhdr.hWndFrom = Listview_GetHeader (hWndLV)

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

                    Comment


                    • #11
                      Ah, I see, it's all in here http://msdn2.microsoft.com/en-us/library/ms671799.aspx

                      Comment


                      • #12
                        After a bit of self-education I found the code below (couple of minor changes) in this very forum posted by Jose Dario Vega Higuera, which puts an editbox over the listview "cell". All that's needed now is the item and subitem indices:

                        '--------------------------------------------------------------------------------
                        FUNCTION SDCLVEditField ( hDlg AS LONG, iDCtl AS LONG, nRow AS LONG, nCol AS LONG, cType AS BYTE) AS LONG

                        'Creates an edit field

                        LOCAL Dummy AS STRING, szText AS ASCIIZ * 255, xy AS RECT, hCtl AS LONG
                        LOCAL tLVC AS LV_COLUMN

                        LOCAL x1 AS LONG, y1 AS LONG, x2 AS LONG, y2 AS LONG

                        LOCAL Dummy() AS STRING
                        DIM Dummy(10)

                        FOR x1 = 0 TO 9
                        Dummy(x1) = "TEST 0" & TRIM$(STR$(x1))
                        NEXT

                        CONTROL HANDLE hDlg, iDCtl TO hCtl
                        IF ListView_GetItemCount(hCtl) THEN
                        ListView_GetItemText(hCtl, nRow, nCol, szText, SIZEOF(szText))
                        ListView_GetSubItemRect(hCtl, nRow, nCol, %LVIR_BOUNDS, VARPTR(xy))
                        IF nCol = 0 THEN
                        tLVC.mask = %LVCF_WIDTH
                        ListView_GetColumn hCtl, 0, tLVC
                        xy.nRight = tLVC.cx
                        END IF
                        DIALOG GET CLIENT hDlg TO x1, y1
                        DIALOG UNITS hDlg, x1, y1 TO PIXELS x1, y1
                        IF xy.nRight > x1 THEN ' Check if Edit fits in Dialog
                        ListView_Scroll hCtl, (xy.nRight - x1) * 3, 0
                        END IF
                        CONTROL GET LOC hDlg, iDCtl TO x1, y1 ' Check if Edit fits in Dialog
                        IF xy.nLeft < x1 THEN
                        ListView_Scroll hCtl, (x1 - xy.nLeft) * -3, 0
                        END IF
                        y2 = xy.nBottom - xy.nTop
                        ListView_GetSubItemRect(hCtl, nRow, nCol, %LVIR_BOUNDS, VARPTR(xy))
                        IF nCol = 0 THEN
                        tLVC.mask = %LVCF_WIDTH
                        ListView_GetColumn hCtl, 0, tLVC
                        xy.nRight = tLVC.cx
                        END IF
                        DIALOG PIXELS hDlg, x2, y2 TO UNITS x2, y2
                        DIALOG PIXELS hDlg, xy.nLeft, xy.nBottom TO UNITS xy.nLeft, xy.nBottom
                        DIALOG PIXELS hDlg, xy.nRight, xy.nTop TO UNITS xy.nRight, xy.nTop

                        CONTROL ADD TEXTBOX, hDlg, %IDC_TEMP, "", xy.nLeft + x1 + 1, xy.nTop + y1 + 1, xy.nRight - xy.nLeft, y2, _
                        %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %WS_TABSTOP OR %ES_LEFT OR %ES_AUTOHSCROLL, _
                        %WS_EX_LEFT OR %WS_EX_LTRREADING
                        END SELECT
                        Dummy = TRIM$(szText)
                        CONTROL DISABLE hDlg, iDCtl
                        CONTROL SET TEXT hDlg, %IDC_TEMP, Dummy
                        CONTROL SEND hDlg, %IDC_TEMP, %EM_SETSEL, LEN(Dummy), LEN(Dummy) ' End of text
                        CONTROL SET FOCUS hDlg, %IDC_TEMP
                        FUNCTION = 1
                        END IF
                        END FUNCTION
                        Last edited by Chris Holbrook; 24 Nov 2007, 11:28 AM. Reason: minor code changes

                        Comment


                        • #13
                          so the WM_NOTIFY/HDN_ENDTRACK is a bit of a red herring because if you make the edit box dynamically then you will be doing it on WM_NOTIFY/NM_DBLCLK and you then have a NMLISTVIEW structure containing the item/subitem indices with which to feed the edit box creation function posted above. And while you are editing, the edit control has focus so you can't resize the column at that point. That makes it simpler.

                          Comment


                          • #14
                            >so the WM_NOTIFY/HDN_ENDTRACK is a bit of a red herring....

                            ????

                            Although in this case you'd never use it - because you are ending the edit by destroying the edit control as soon as you get WM_COMMAND/EN_KILLFOCUS - it's what you asked!

                            If the correct answers lead you astray, ask better questions!!


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

                            Comment


                            • #15
                              If the correct answers lead you astray, ask better questions!!
                              I wasn't complaining, just iterating, don't stress!

                              Comment

                              Working...
                              X