Problem concatenating text in textbox
I have a really strange problem.
I have a textbox "myTextbox" and a listbox "myList" which shows a list of strings e.g "AAA", "BBB", "CCCC".
When the user clicks on an item from the listbox the text must be appended to the end of whatever is in myTextbox with a space preceeding it. e.g " AAA".
The user must never be allowed to delete the added text.
The user must be allowed to manually enter text in the textbox but it must always be in front of the added text.
They must never be allowed to type over the added text or after the added text.
I have been trying to get my head around this for a day now and cannot figure it out.:mad:
Can anyone point me in the right direction?
Has anyone had a similar request to deal with?
Thanks in advance:wave:
Re: Problem concatenating text in textbox
Why does the text from the ListBox have to be added to the same TextBox the user is editing? A String is a String. Just use two TextBoxes with the second being read-only or use a Label instead. You can then just join the Text from the two controls in code when you're done.
Alternatively, you could probably use a MaskedTextBox and continually change the Mask as the user types. The data from the ListBox would be literal characters forming part of the mask.
Re: Problem concatenating text in textbox
Quote:
Originally Posted by
venerable bede
I have a really strange problem.
I have a textbox "myTextbox" and a listbox "myList" which shows a list of strings e.g "AAA", "BBB", "CCCC".
When the user clicks on an item from the listbox the text must be appended to the end of whatever is in myTextbox with a space preceeding it. e.g " AAA".
Until here everything was easy, using "MyTextbox.text = MyTextBox.text & " " & myList.List(myList.ListIndex)" in the _click event of the ListBox should do the trick.
Quote:
Originally Posted by
venerable bede
The user must never be allowed to delete the added text.
The user must be allowed to manually enter text in the textbox but it must always be in front of the added text.
They must never be allowed to type over the added text or after the added text.
these parts make the problem, I wouldn't use a textbox for that, since you would have to manually "disable" most of the features of a textbox!. Why not use a Label. The only problem remaining would be the "The user must be allowed to manually enter text in the textbox but it must always be in front of the added text." I'd use another textbox for that.
Re: Problem concatenating text in textbox
Thanks for the replys but unfortunatly I must use a single textbox. It's in my spec and I have no choice in the matter.
Now you know why I am pulling my hair out.
It seems easy on the surface but it is far from it.
Re: Problem concatenating text in textbox
Just out of curiosity, who wrote the spec? An applications designer/architect (ie, a fellow geek) or the business analyst?
I'm hoping that it was the BA that wrote that spec. And the truth is, they have no business writing that kind of specification. BA's should be writing specs that say WHAT the system needs to do ("system needs to have the ability to enter information....") but not HOW it should be done ("entry will use a text box with the following restrictions").
If it was written by technical person then.... *cue the rolling of the eyes*
Last thing to note - is your shop so inflexible that you can't take it back to the person that wrote the spec and explain "Hey this isn't going to work, here's why... X, Y, Z. I think we should to it this way instead A, B, C."
-tg
Re: Problem concatenating text in textbox
You are correct.
It was not written by a developer.
The general rule is "If it is possible (which in this case it is) it does not matter how difficult it is. It must be done".:mad:
It is a pain in the backside.
I knew I should have been a hairdresser.
Re: Problem concatenating text in textbox
Except what's possible and what isn't shouldn't be left up to the non-technical. It's possible that I could swell up like a giant blueberry... doesn't mean I want it written out in a spec.
That's the kind of spec I kick back for re-write or removal. It doesn't belong.
Layer two textboxes, modify their borders so they look like one... embed them into a picture box so you get a border.... make the one text box readonly.... you could also then make it a user control... make it act and look like one text box.
-tg
Re: Problem concatenating text in textbox
I knew this would stump you guys.
I've been looking at it for an age and I'm pulling my hair out.:mad: