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
4 1724
My appologies. The code is written in Visual Basic 6..
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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()
names =
for n in names:
|
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 want to do this as the selections are
being made not after-the-fact after all selections are made.
Thanks!
Sally
|
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 to highlight them in the
listbox within the datagrid control.........
Thanks,
Bill...
>-----Original Message-----
|
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 a denormalized mirror of the
database, but I'm not having much luck getting the selection logic down (I
haven't found a 'hook' where I can access the listbox object as an object to
set the listitem's selected property before it gets rendered)..
...
|
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 belongs to a panel control. In
the Page_Load event, the panel listbox control may be moved from one panel
to another depending on selections that the operator makes. Everything
seems to work fine except for one thing. The selections that are made in...
| |
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 that would
Populate another Listbox/datagrid. Then it would cycle through the selections made in the populated listbox/datagrid and do some calculations. The calculations made would have to add the first two numbers in the populated...
|
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 server).
The RemoveFiles function is being executed, bu I have a feeling the
selections are being cleared beforehand.
There is a Page_Load function which repopulates the listbox. Could
this be getting in the way?
|
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 amount applied for has been entered. This should
populate an unbound listbox to display their selections. A user can
select one or more sets of product types and the amount applied for.
They should also have the functionality to remove a 'set' if...
|
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 selections made but I woul also like to highlight and maintain the highlighted items as I make additional selections. I can maintain the highlighted selections from listbox to listbox, but can't seem to figure out how to maintain the selected...
|
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 another
tecnique.
As you may know, in softwares like Windows Media Player or Winamp
playlist has a listbox and it can be selected in 2 types. First type
refers to player's own selection and second selection type can be done
by user to look for...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |