Announcement

Collapse
No announcement yet.

Combobox with multiline per item?

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

  • Combobox with multiline per item?

    Hi All, I'm looking for a solution for a combobox that can provide and display multiple lines per item so that user can select an item with a long string.

    I tried to get the below Hurricane Categories into a large combobox but it inevitably fail to display in multiline. It display each item all in one LONG line!

    Cat1 Very dangerous winds will
    produce some damage. Winds range from 74 to 95 mph.
    Falling debris could strike people, livestock and
    pets, and older mobile homes could be destroyed.

    Cat2 Extremely dangerous winds will
    cause extensive damage
    Winds range between 96 and 110 mph during a Category 2
    hurricane.

    Cat3 Devastating damage will occur. Winds range from 111 to 129 mph.
    There is a high risk of injury or death to people

    Cat4 Catastrophic damage will occur
    Will blow out most windows on high-rise buildings
    and uproot most trees.

    Cat5 Catastrophic damage will occur
    winds are 157 mph or higher. A high percentage of
    frame homes will be destroyed.
    Click image for larger version  Name:	Combo selection.png Views:	2 Size:	16.6 KB ID:	818114

  • #2
    here's the program
    Attached Files

    Comment


    • #3
      As you can see in my program code as below that I tried to separate out each item into multiple lines using $CRLF

      Code:
      '============================
      SUB SetupCmbStrings
      
       ' set up the custom combo box with long strings
        LOCAL  ci AS LONG
        ci = 5
        REDIM PRESERVE CBSelType(1 TO ci)
      
          ' Front patch by 2 blank space for display purposes
          CBSelType(1) = SPACE$(2) + "Cat1 Very dangerous winds will produce some damage." + $CRLF + _
                         " Winds RANGE FROM 74 TO 95 mph. " + $CRLF + _
                         "Falling debris could strike people, livestock and pets, and older" + $CRLF + _
                         " mobile homes could be destroyed."
      
          CBSelType(2) = SPACE$(2) + "Cat2  Extremely dangerous winds will " + $CRLF + _
                         "cause extensive damage. Winds range between 96 and 110 mph"
      
          CBSelType(3) = SPACE$(2) + "Cat3  Devastating damage will occur. Winds range from 111 to 129 mph. " + $CRLF + _
                         " There is a high risk  of injury or death to people"
      
          CBSelType(4) = SPACE$(2) + "Cat4  Catastrophic damage will occur. Will blow out most windows " + $CRLF + _
                                    " on high-rise buildings and uproot most trees."
      
           CBSelType(5) = SPACE$(2) + "Cat5  Catastrophic damage will occur. Winds are 157 mph or higher." + $CRLF + _
                           "A high percentage of frame homes will be destroyed. "
      
      
      END SUB
      but its display in the combobox is that each item is being displayed as one line only and not multiline???
      it ignores the $CRLF altogether ?

      it kinda make me think I should increase (the already large combobox size) length of the combobox to accomodate
      these long item's lines.

      It is something I missed out in the combobox style ? which prevents it from having a multiline?
      the below lines are located in the ComboSel_wd2.inc which creates the combobox

      Code:
      CONTROL ADD COMBOBOX, hDlgCb, %IDcb_Combox,CBSelType() , 7, 16, 414, 320, _
                    %CBS_OWNERDRAWFIXED OR %CBS_HASSTRINGS OR %CBS_DROPDOWNLIST OR _
                    %CBS_SORT OR %ES_MULTILINE OR %WS_TABSTOP ,%WS_EX_STATICEDGE
      appreciate all help

      Comment


      • #4
        Styles for different controls don't mix between controls. COMBOBOX styles are prefixed CBS ComboBoxStyle. %ES_MULTILINE is for TEXTBOX, called Edit by Microsoft, so prefix ES for EditStyle.

        Each style is a bit in the style& variable. What each bit does for each kind of control may, or may not, be the same for other kinds of controls. The equate names (like %ES_MULTILINE) ids what style a particular bit number is for in each particular kind of control (or other kind of window like DIALOG).

        %ES_MULTILINE is bit 2 set. (value of 4 when considered alone). COMBOBOX does not have a bit 2 style. It did nothing in this case, could have had a completely unwanted affect. For example, bit 2 set in a button style would make that control a radio button, not a push button with multiline label. %BS_MULTILINE is bit 13 set.

        Styles like %WS_TABSTOP are standardized across control kinds.

        Maybe someone will post some code to use with ownerdrawn, but a standard COMBOBOX is single line per item within the list portion.
        Dale

        Comment


        • #5
          Thanks Dale, there must be an owner drawn combobox in this forum as I can find many owner drawn stuff

          Comment


          • #6
            Note I said "maybe". It is also maybe it is not possible, or doing it makes it not a combobox anymore. So "must be" is not a true statement
            Dale

            Comment


            • #7
              Brainstorm (again maybe). Short line in list. ToolTip with longer line when hovering over item in list.
              Dale

              Comment


              • #8
                Tim,

                Your sample code is owner drawn..

                Try these mods to the ComboSel_wd2.inc file.
                Code:
                ..
                  ' nicer with a bit bigger font, so increase line height in control - adjust to own liking.
                  CONTROL SEND hDlgCb, %IDcb_Combox, %CB_GETITEMHEIGHT, 0, 0 TO i    'get current line height
                  CONTROL SEND hDlgCb, %IDcb_Combox, %CB_SETITEMHEIGHT, -1, i + 2    'increase in edit part..
                  CONTROL SEND hDlgCb, %IDcb_Combox, %CB_SETITEMHEIGHT, 0, (i + 2) * 4    'increase in list..
                 
                ..
                           DrawText @Cblpdis.hDC, zTxt, LEN(zTxt), @Cblpdis.rcItem, %DT_WORDBREAK '_
                 '                    %DT_SINGLELINE OR %DT_LEFT OR %DT_VCENTER
                Rgds, Dave

                Comment


                • #9
                  never mind
                  found in Tim's zip

                  came back to say I found it about the same time Dave posted
                  Dale

                  Comment


                  • #10
                    ComboSel_wd2.inc is in the zip file attached to post no.2
                    Rgds, Dave

                    Comment


                    • #11
                      Thank you Sir Dave, this really works with your modifications

                      Comment


                      • #12
                        After adding more Categories of Hurricane, I have encountered another problem, the size of the combo box being display is very large as depicted below

                        Click image for larger version

Name:	Huge combobox.png
Views:	108
Size:	73.7 KB
ID:	818127

                        how to limit the size of this box display ? Make the combobox display smaller and any additional categories can be navigated downwards with a scroll button
                        how do I do this ?

                        as a huge combobox would put users off , it is best to have the combobox be make to display say only 4 rows of categories at a time and to allow user to scroll down this
                        combobox to select other additional categories.

                        Comment


                        • #13
                          Here's the new changes of the code
                          Attached Files

                          Comment


                          • #14
                            A Listview control can provide multiple lines of text, with multiple selections either by clicking (Mouse or keyboard) or by checkbox. You will have to owner draw it. (see WM_NOTIFY/NM_CUSTOMDRAW . Numerous examples here in source code forum).

                            An owner-drawn listbox can do so as well without checkboxes (I know Borje Hagsten has a demo of this here)
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Tim,

                              It's a question of style
                              Code:
                                 CONTROL ADD COMBOBOX, hDlgCb, %IDcb_Combox,CBSelType() , 7, 16, 400, 120, _
                                            %CBS_OWNERDRAWFIXED OR %CBS_HASSTRINGS OR %CBS_DROPDOWNLIST  _
                                             OR %CBS_NOINTEGRALHEIGHT OR %WS_VSCROLL,%WS_EX_STATICEDGE
                              Rgds, Dave

                              Comment


                              • #16
                                Originally posted by Dave Biggs View Post
                                Tim,

                                It's a question of style
                                Code:
                                CONTROL ADD COMBOBOX, hDlgCb, %IDcb_Combox,CBSelType() , 7, 16, 400, 120, _
                                %CBS_OWNERDRAWFIXED OR %CBS_HASSTRINGS OR %CBS_DROPDOWNLIST _
                                OR %CBS_NOINTEGRALHEIGHT OR %WS_VSCROLL,%WS_EX_STATICEDGE
                                It would be preferable to make the CB list a bit longer, change the height from 120 to something like 300 :

                                Click image for larger version

Name:	CBList.jpg
Views:	91
Size:	132.3 KB
ID:	818133

                                Comment


                                • #17
                                  I salute to both of you Dave and Stuart , my program finally works by taking your advice. Thanks to all

                                  also note that there are only 5 categories of hurricane, I was just testing 12 categories here to check how the owner drawn combobox can work
                                  with multiple entries!

                                  Comment


                                  • #18
                                    Originally posted by Tim Lakinir View Post
                                    I salute to both of you Dave and Stuart , my program finally works by taking your advice. Thanks to all

                                    also note that there are only 5 categories of hurricane, I was just testing 12 categories here to check how the owner drawn combobox can work
                                    with multiple entries!
                                    I wondered where you came up with more than the 5 of the Saffir-Simpson scale so went looking and found this : :
                                    The internet really is a weird and wonderful place.
                                    https://hypotheticalhurricanes.fando...etical_ratings


                                    Comment


                                    • #19
                                      The 12 categories were my own concoctions maybe applicable to storms on Jupiter or Venus ? sooner or later we may have to go to another planet

                                      Comment

                                      Working...
                                      X