473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Listbox Selections

Does anyone know of a way to take the contents of a multiline textbox from a form, then when I open another form with a listbox on it, have the items matching the textbox items be higlighted in the listbox?

Example:
User opens form with textbox that has 2 items in it, say "BDU1" and "BDU2". He clicks on an Edit button and open a form that has a listbox that contains selections loaded from an Access table. I would like the "BDU1" and "BDU2" in the listbox to be selected when the form opens since it was in the textbox.

Thank you in advance for any help
Apr 17 '07 #1
4 1708
My appologies. The code is written in Visual Basic 6..
Apr 17 '07 #2
Killer42
8,435 Expert 8TB
My appologies. The code is written in Visual Basic 6..
Thanks for telling us the version - people usually don't think of it.

Which part is the problem? Getting the lines out of the multiline textbox, or doing the selections in the listbox, or what? And do you actually want to select the items in a listbox which may also contains other items, or just populate the listbox with only these items?

(Tip - to select things in a listbox, see the .Selected property)

Edit: Sorry, I just re-read your post and see that some of these are already answered there.
Apr 17 '07 #3
Thanks Killer42. Actually, I am not sure what the best way to get the text values other than possibly the split function as the textbox could have several selections, like BDU33, BDU31, BDU34. Each is seperated by a vbcrlf and the textbox is a multiline textbox with vertical scroll bars. The listbox on the other form is populated from a table in Access 2003 and I just want to highlight (select) the items in the listbox that are in the textbox.

To help explain, what the user is doing is opening a form that contains data. That is where the textbox is. They click on an edit button which opens another form that contains the listbox so they can edit the data that is already in the textbox. The reason for wanting to highlight the items in the list box based on the text in the textbox is so they will see what was already in the textbox and can make their changes and then save it back to the textbox. Also, when they click on the edit button, I thought having the textbox clear out it's contents and then highlight what was in the textbox in the listbox, this would prevent duplicate entries from ending up back in the textbox when they closed the edit form containing the listboxes.

Hope this makes sense.
Apr 18 '07 #4
Killer42
8,435 Expert 8TB
I think it sounds as though you're on the right track. I'm not going to comment on the overall situation, just the technical aspects. Or to put it another way, I'm more interested in the how than the why. (I never was much good with the “big picture”.)

I think that you're right, Split is probably the simplest way to pull the lines out of the textbox. However, I suspect it won't work out very well, because I assume (correct me if I'm wrong) that it splits on a specific character. Since the line break consists of two characters (CR+LF), this may be a problem.

Of course, you can always fall back on the simple brute-force approach. Loop through your text, character by character, and grab off each line as you hit the CR (remembering to then skip over the LF, of course). A slightly more efficient method might be to use the Instr() function to find the end of each line, and probably Left() or Mid() function to grab the line.

Selecting/highlighting the items in the listbox is simply a matter of setting their corresponding .Selected property. However, you need to set the .MultiSelect property appropriately (check your doco to determine the setting you want).

So, I suppose you can just loop through your array of entries pulled from the textbox, and for each one, loop again through the listbox contents and set .Selected(n) if it matches. If the listbox entries are unique, of course, you can drop out of the loop at that point rather than continuing through the rest of them.

Wel, hope that gives you a few ideas to play with.
Apr 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Harlin Seritt | last post by:
I am trying to poll selections from a listbox but can't seem to get it to work correctly. class pollstuff: def __init__(self, master): self.listbox = Listbox(master) self.listbox.pack() ...
2
by: Sally | last post by:
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I...
0
by: bill yeager | last post by:
Duray, it helps in regards to knowing how to get the items that were selected in the lisbox, but I'm going in reverse --- after I get the items from the db that were selected, I'd like to be able...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
0
by: Ken Varn | last post by:
I have a strange problem with a databound listbox. It may be because of how I use it, but I am stumped by this behavior. Here is the scenario: I have a multiselect databound listbox that...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
2
by: ProgrammerChicago | last post by:
I'm not sure if this is the result of the postback behavior or my own code, but for some reason my onclick function is not detecting listbox selections (It's meant to delete files uploaded to the...
6
by: BerkshireGuy | last post by:
On an unbound form, I have a combobox called 'cboproducttype' and a text box called 'txtamountappliedfor'. I have an Add button that I would like the user to be able to hit once a product and...
0
by: Gunnar Hurtig | last post by:
Hi All I am relatively new to Tkinter and am putting a wraparound to the ATNF ASAP program. In one part I present several long lists in list boxes for selection. My code will remember the multiple...
4
by: kimiraikkonen | last post by:
Hi, I have a odd but a known question about listbox. I know listbox control can provide multi-select, multi-extendend selections. But i wonder if this selection type belongs to them or it has...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.