How do I Use a ';' Within the Value of a Column in a ComboBox or ListBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mihail
    Contributor
    • Apr 2011
    • 759

    How do I Use a ';' Within the Value of a Column in a ComboBox or ListBox

    Here is a "solution" to edit an item in a list (the example is for a list box but should work for a combo box too)


    I make some "discoverie s" trying to develop that code:

    Is no way to add to a list box an item like this:
    I am a coder; The best one !
    When I try to add this item (using .AddItem method) to a list box with only one column, only first part (I am a coder) has been added. The second part has been lost.
    For a list box with many columns this item is split: first part in first column, the second part in the second column.
    So is it possible to add, in a single "cell" an item that contain the ";" sign ?

    Another thing:
    Is no way to deselect all items.
    Somewhere I read that
    Code:
    ListBox = ""
    should work.
    Yes. This work until... an item in the list box is "". If this happen, this "empty" item will be selected.

    Of course, as a human I can use this:
    Code:
    ListBox = "ThisStringNeverWillAppeareInMyListBox"
    But as coder I can't be sure that even this "crazy" string will not appear at a moment.

    If you have some solution to this problems please let me know.

    Thank you !
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    If you look in the Help system (Context-Sensitive Help) you'll see that you can pass multiple values in a single string value with semi-colon (;) separators.

    Comment

    • Mihail
      Contributor
      • Apr 2011
      • 759

      #3
      Yes, NeoPa. I know that.
      My question is how to put a string that contain semi-colons in a single "cell" in a list box ? How to avoid that this string to be split ?

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Sorry Mihail. I was confused by the question, but now I read it again it's clear that you did include that in the explanation. I read it badly.

        Now, that's a good question. Help has nothing to say on the matter so I suggest you experiment with some of the typical 'string escape' characters (EG. '\'). Doubling up may be worth a try, but I'd guess that would simply result in an empty column value.

        Comment

        • Mihail
          Contributor
          • Apr 2011
          • 759

          #5
          No problem, Adrian. Seems that my "English" is hard to understand even for you, an English guy.

          I never have heard about 'string escape' characters.
          I'll search on Google, of course, but if you are so kind to explain that in a little bit more details I'll thank you (again) very much.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            Originally posted by Mihail
            Mihail:
            No problem, Adrian. Seems that my "English" is hard to understand even for you, an English guy.
            It's because I'm English, rather than in spite of it, Mihail ;-)

            What I'm suggesting is simply to try :
            Code:
            "I am a coder\;The best one !"

            Comment

            • Mihail
              Contributor
              • Apr 2011
              • 759

              #7
              Thank you !
              No success.
              Again 2 strings: I am a coder\ and The best one !

              OK. I decide to not waste more time on this subject.
              Thank you again !

              Comment

              • Hennepin
                New Member
                • Oct 2009
                • 25

                #8
                Wrap the string with ; with quotes.
                Code:
                Me.List0.AddItem """I am a coder;The best one !"""

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  Originally posted by Mihail
                  Mihail:
                  OK. I decide to not waste more time on this subject.
                  That's lucky, because I'm out of ideas anyway :-D

                  If I find anything I'll post but basically, as of now, I have no idea if it's even possible :-(

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    Except that Hennepin has already provided a perfect answer. Nice one.

                    Comment

                    • Mihail
                      Contributor
                      • Apr 2011
                      • 759

                      #11
                      Indeed. It is the best answer.

                      Also I have verify this:
                      Code:
                      Me.List0.AddItem """I am a coder;The best one FirstColumn !"";""I am a coder;The best one SecondColumn !"""
                      for a list box with 2 columns and work perfect.

                      Thank you, Hennepin !

                      Comment

                      Working...