Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Listbox: Change Text Of Selected Item


hi all,

just wondering if anyone knows a way of changing the text of the selcected item in a list box?

for example: if i have a listbox with the following list items:

one
two
three
four

and "two" is selected, and i need to change its text to "this one".

i would like to avoid regenerating the list by clearing it and adding all the items again if possible.


thanks for your time and consideration,

mojoinst




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
(? Help) Change Listbox Selected Text Without .additem Or .remove Item
Hi, I browsed through posts and didnt see this question elsewhere so I hope I didnt miss it if it was answered already. If so im sorry.

I was wondering if there is anyway to change the selected text entry for a list box without adding or removing an item.

Example: If there were these options in a list box:

A
B
C

and "B" had been selected by the user is there anyway to change "B" to "D" without using the .additem or the .remove command? If you need me to restate or clarify what im asking please let me know and Ill repost as soon as I see it. Thanks for any help I get in advance.


- Sidenote: I would use a loop and simply add them into another list box and back into that one in a different in the correct order but theres some sticky and touchy coding done on the list box's _click statement that really wouldnt make such a loop possible....if this sidenote didnt make sense sorry its 5 am .

How Do I Change The Font To Bold For The Selected Item From A Combobox Or A Listbox??
I populated my combobox from a database, and I will like to change the font from normal to bold for only those items that had been selected.
Could somebody help me please?
Thanks

Change ListBox Item Text?+ Change Item Color Or Status?
hi
I'm new to VB. I want to change the text of a ListBox item.
I used AddItem to add items.
Then I tried to change a selected item using lst.Text = "somethingNew", but it doesn't work...
Pl. help

And need to know.. how to change the color of an item or status(disable) of an item???

Thanks

Change ComboBox Text When Item Selected
I though this would be easy, I have a ComboBox style set to 0, and the list is populated from a dB. What I want to do is have the default Text change to the selected item when the list reloads. Here is the code;
Code:' Populate the Type list
    cboEntryType.Clear
    If Len(sqlQuery) > 2 Then
        cboEntryType.Text = sqlQuery
    Else
        cboEntryType.Text = " All"
    End If
    
    For i = 0 To m_TypeRows

    str9 = " " & m_varTypes(0, i) & " " ' Entry Types
        cboEntryType.AddItem str9
    Next
sqlQuery is a parameter sent to another function that returns the ListItems, if I set a watch on the var sqlQuery it does indeed have a valid value, but when the box is displayed the Text is " " with focus on the box.

How Can I Set The Text To Bold In The Selected Item Of A Listbox.
how can I set the text to bold in the selected item of a listbox. I need it to be like that until another file listitem is double clicked.

Change Color Of Selected Text In A Listbox
I'm trying to add text to a listbox and have different text be different colors to represent either an open or closed file to match some other software we currently use. Does anyone know how to change the text color inside a list box. I will need to be able to use 3 different colors.

Thanks in advance for any help.

Populate A Listbox Based On A Selected Item In Another Listbox
Ok...I am stumped.

I have a single form that has 3 list boxes. I have 4 public strings containing various values. Based on the selection from lstBox1, I need to populate the ListBox2 and ListBox3 list from values in the public strings. Clear as mud?? That is what I thought!

Example string variable

strLuxury = """Hand Wash"" ""Hand Wax"" ""Check Engine Fluids"" ""Detail Engine Compartment"" ""Detail Under Carriage"" ""Fragrance"" ""Shampoo Carpets"" ""Shampoo Upholstery"" ""Scotchgard"""

ListBox1 contains the following:

Standard
Deluxe
Executive
Luxury

ListBox2 is empty, but is contained in a frame indicating Exterior Options
ListBox3 is empty, but is contained in a frame indicating Interior Options

If Luxury is selected in ListBox1, then ListBox2 should contain
Hand Wash
Hand Wax
Check Engine Fluids
Detail Engine Compartment
Detain Under Carriage

And ListBox3 should contain
Fragrance
Shampoo Carpets
Shampoo Upholstery
Scotchgard

If Fragrance is present in ListBox3, a seperate dropdown box should appear allowing selection of the appropriate scent.

Yes, this is a homework assingment.

Thank you in advance for your help!
Mark

.: Please Help: Copy Selected Item(s) From A ListBox To The Other ListBox..
Hi everyone!

I'm having problem with copying file to another Listbox, please help..
So, in this case, I have two ListBoxes where the 1st ListBox holds several items..
I need to copy the selected item to the other listbox 'without' a repetition, I mean.. the same item won't copied anymore..
When the user tries to copy the item which have already been in the ListBox2, then a messagebox will pop up to warn the user of the existing item.... So, how should I do that??


Thanks a lot

Listbox Selected Item
Hello again!

I was wondering if anyone knew how to make the selected item from a listbox appear in a text box.

For instance List1 as the list box and Text1 as the text.box? Is it just one of the properties because I have not be able to find it.

Thank you for all your help!

Always Have Last Item In Listbox Selected
How can I make it so the last item in a listbox be selected, even after new items are added. For instance, lets say I had four items in a listbox like this:

I'm one
I'm two
I'm three
I'm four

At this point I'd want "I'm four" to be selected and if I added another item like this:

I'm one
I'm two
I'm three
I'm four
I'm five

Then at this point I would want "I'm five" to be selected. Does anyone know of a way to do this ?

Thanks in advance for any help!

Selected Item In A Listbox
how do i find the selected item in a listbox???

How Do You Get A Selected Listbox Item's Name?
i have a question. how do you get a selected listbox item's name? what i mean is if i selected "yo" from my listbox i want text 1 to be yo when i click a command button or something. plz help. thanks in advance

Set A Selected Item In Listbox ?
I'm searching for a way to code base set a selectedindex for a listbox in MS Access 97

Anyone can help me out on this ?

ListBox Selected Item
Hi.

I need some help on how about doing this:

When a user selects an item in a list box then that item is shown in a text box.

Help, please.



Edited by - Philboy on 9/12/2004 12:30:41 AM

Scroll To Selected Item In Listbox
Hi guys,

I'm in Access. I have a form with a listbox and a combobox with the same values. The user selects the value in combobox, clicks the button, and the same item gets selected in the listbox. The problem is that the listbox doesn't scroll to the selected item automatically. Here is my code:

For i = 0 To Me.storeNumber.ListCount - 1
If Me.storeNumCombo.Value = Me.storeNumber.ItemData(i) Then
Me.storeNumber.Selected(i) = True
End If
Next i

This code selects an item in the listbox every time I press the button leaving previously selected items selected too.

I've been looking for solution suitable for me and found this code:

For i = 0 To Me.storeNumber.ListCount - 1
If Me.storeNumCombo.Value = Me.storeNumber.ItemData(i) Then
Me.storeNumber.setFocus
Me.storeNumber.ListIndex = i
End If
Next i

It does scroll to the selected item. However, every time I click the button it clears previously selected item and selects the new one that I selected in combobox. And I don't need that clearing. Any ideas on how to avoid this? Thanks in advance.

Changing Value Of Item Selected In Listbox
How can I change the value of an item selected in listbox by clicking a command button?

I'm really looking to do something like this:

If an item is selected in ListBox1 and I press Command1 then make the selected item in ListBox1 the value of the selected item in Listbox1 minus 1 character...


If anyone can help I'd be greatly appreciative!

Selected Listbox Item Into A Second Funcion.
I looked everywhere and didn't find an clues to solve my problem. One of wksheets as all my items listed alphabetically. Column A all the a's, B all the b's, etc. I have a userform with a listbox that displays one of my columns based on which letter the user chooses (from my main userform). Each column has a different number of entries, so each respective listbox has a different number of lines in it.

On the same userform (with the listbox) I have a command button that runs a search and display function based on what item is selected in the listbox.
Basically this funcion searches for whatever item name is selected in the list box (the actual text).

I cannot figure out how to get my selected listbox line to display its text in my second function

If C.Value Like "item name" Then.....

So I need the text from the listbox item, to display as item name in my second function

Any help is awesome. Thanks in advance.

Showing A Selected Item In A Listbox
I've got a textbox which the user can input text. I also have a list of already existing items. Doing the search for the item, isn't a problem. However, I wish to select the item, and then make sure it is in the visible portion of the list box.
Actually, getting the item selected isn't a problem. It's getting the selected item into the visible portion of the listbox that is giving me problems. Anyone have any ideas?

Removing A Selected Item From Listbox
I'm not familiar with using the For statement but I gave it a try.


Code:
For i = 1 to 9999
i = lstsFiles.SelCount
lstsFiles.RemoveItem (i)
Next

This didn't work. It gave me an error on lstsFiles.RemoveItem (i). I assume I have it wrong. I removed that line of code, ran it and it froze VB. Now I've gotta restart my program.

Need Some More Help! {Detecting If Listbox Item Is Selected}
Say i had an item in a listbox called Check1. How would you detect if Check1 is selected?

How To Make Item In Listbox Selected
i was wondering if anyone could tell me how to make a listbox item (at whichever index) selected...like say my list is

apples
oranges
banannas
pears

how do i make the oranges text in the listbox show up selected?

Removing Listbox Selected Item
How do I remove a user selected item in a listbox. Right now I have....


Code:
Private Sub Command3_Click()
lbo(RemoveItem) = lbo(SelectedItem)
End Sub
Where "lbo" is the name of the listbox. But that just yields a command button that does nothing at all.

I have anoter selected item that works similar (which works), where it gets the selected item in the listbox and sends it to the web browser


Code:
Private Sub Command1_Click()
Denlou.WebBrowser1.Navigate lbo(SelectedItem)
Unload favorites
End Sub
And I can't remove the equals sign because it returns "Expected: End of Statement"

Anyone know what to do?

Deleting A Selected Item From A Listbox
Hi there,
I`ve just joined this forum. I was wondering if anyone could help me?

I`ve made a listbox, populated with data from a table in access, with the column heading test.

I want to be able to select an item from the listbox, click on a button and then delete the item from the listbox and database. I have managed to do this, however the item deleted from the database is the first item and not the selected.

Any ideas?

Heres my code....


Private Sub CommandButtonDelete_Click()

Dim vConnection As New ADODB.Connection
Dim vRecordSetTest As New ADODB.Recordset
Dim vConnectionState As Integer

Set vRecordSetTest = New ADODB.Recordset

vConnection.ConnectionString = "data source=G:FilingLabel.mdb;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;"

vConnection.Open

vRecordSetTest.Open "TableTest", vConnection, adOpenKeyset, adLockOptimistic

vRecordSetTest.Delete
ListBox1.RemoveItem ListBox1.ListIndex

End Sub

Delete Selected Item In Listbox?
Now I need a little help with deleting a item in the list box.

so the name that is highlighted I wanna remove from the item list but only that item not the whole list.

Thanks !

Telling Which Item Is Selected In A Listbox.
How can I tell what item is selected in a listbox?
edit- believe I figured it out, list1.selected(0)? And how can I put that in a select case? I don't know what I'd put instead of 0 for select case list1.selected(?)

Easy - Tell If Last Item In Listbox Is Selected.
What is a quick and simple way I can tell if the last item in a listbox is selected ? There is no multi-select enabled in the list either. I am doing it using listcount, and index but I get the feeling I am making it way more complicated then it needs to be. If you have an answer could you throw it in an if statement so that it will put up a msg box saying either "Last item selected", or "Last item not selected". ~Many Thank, Bryan J. Casler

Which Item Is Selected In A ListBox In Another Program
How do I tell which item is being selected in the listbox of another program?

Removing Selected Item From Listbox
Hello

How do I remove a selected item from a listbox?

ps Sorry form the noobieness

Thanks
SgtSlayer

Remove A Selected Item In A Listbox
How do you remove a selected or highlighted item in a listbox?

Checking To See If Item In A ListBox Is Selected
VB Code:
Private Sub lstBuddies_Click()    Dim bSelected As Boolean    bSelected = False      For x = 0 To lstBuddies.ListCount        If lstBuddies.Selected(x) Then            bSelected = True        End If     Next x     If bSelected = True Then        cmdRemoveBuddy.Enabled = True    Else        cmdRemoveBuddy.Enabled = False    End IfEnd Sub


This won't work, but if I put a number in place of x, it will work. Whats that all about?

Deleting A Selected Item From A Listbox
what's up fellow programmers! i wanted to know if there's a way to delete a selected item from a listbox. can anyone help me here? thanks!

Color Of Selected Item In Listbox...
Hello

quick question... is there an API or something to change the color of the highlighting when a record in a listbox is selected? by default it's an ugly blue, and that really doesn't suit my program's tastes ... maybe there is no way, but it would be nice.... thanks for the help!

Remove Selected Item From ListBox
I've been trying to remove the selected item from a listbox but I havn't got it yet. Any help is appreciated.

Listbox Selected Item - Wierd Or Just Me ?
Hi guys,

This has been doing my head in all afternoon. I have a listbox on my form which reads it's data from an Access DB. I also have a normal textbox on my form.

If you select an item in the listbox it becomes highlighted, no problems so far. But, if you then click on the textbox the item un-selects itself. I cannot understand why. I have tried as a test, putting another listbox on the form and filled it's contents at design-time with numbers 1,2,3 etc,,. When this is run you can select an item in the test listbox, click on the textbox and it is still selected.

Any ideas why the first listbox keeps unselecting itself? Is it because the data in it is read from a DB ?

Cheers

How To Delete Selected Item At The Listbox.
Hi everyone,

 I have two list boxes. one of them is for item another one is for price.
example
    Hamburger    $3.00
    Chicken Nugget    $2.00
    Muncher        $1.50

for example the above items are added to the listbox after clicking the picture. if i dont want the chicken nugget, how can i sure when i select it, the value in the two list box are deleted/remove from the list box.

Thank you. all of you in here are great help to me.

from
swatchgal

How To Scroll A Listbox To Display Selected Item
My problem is as follows:

I have a listbox and my program selects a certain item based on coded algorithms. The listbox contains many more items than can be displayed at one time, so I have to use the scroll bar to search through the content of the listbox.

When my program selects an item in a listbox that is not currently in the view frame, I have to find the item by manually scrolling up or down until I can see it.

I would like my listbox to scroll automatically so that the selected item is in view.

I have not found a way to find out which items are displayed, or even to programmatically make the list scroll.

Any suggestion?

Thanks in advance

Retrieve Info From Selected Item In A Listbox
I have managed to display a listbox with similar addresses on for the user to choose from. Those addresses are strings, which combined from a few variables, eg. streetnumber, streetname and postcode.

My next step is to return the chosen ltem back to VB to continue. My problem is how the value for each field (streetnumber, etc) on the selected item could be saved and passed back to VB?? ........

Any help is much appreciated.

Popup Msgbox For No Selected Item In Listbox
How do I got the pop up when no item is selected in the listbox?


Code:
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
SelectLayerByName (ListBox1.List(i))
End If
Next

Send Selected Listbox Item To Textbox
The title says it all. I want to send the selected listbox item text to a textbox. I need to use this in a timer so the selected item will go down the list and it will send it to the textbox every X amount of seconds. Thanks for all your help!

Check If File Listbox Has Item Selected?
How can i check that an item has been selected from the File List Box? This is so it stops you from closing the form unless a file is selected.

Thanks

***INSTANTLY RESOLVED****Selected Item In A ListBox
Hello,
Please have a look at the attached picture & assist me in how can I save the selected name in that ListBox into a Variable...

If Checkbox Checked And Item Not Selected From ListBox BUT...
I have a checkbox and a combobox working together where if the checkbox (commute) is checked but nothing is selected from the list (car, bus, carpool, ferry, etc.) I have a code like this:

If chkCommute.Value And cboCommute.ListIndex = -1 Then 'checked but nothing selected in listbox
MsgBox "You must select a mode of transportation or enter another mode", , "Missing Info"'select a mode since you checked the box
cboCommute.SetFocus
Exit Sub
End if

And it works fine but I want it to go the opposite way - if a mode of transportation is selected but the checkbox not checked THEN...whatever. This info goes to an array that gets printed out. If I select a mode of transportation but don't check the checkbox and press enter the mode of transportation won't show up on the list. What would be a good way to make it come out? Anyone up for this? Thanks.

Frames That Would Follow The Selected Item In A ListBox
Hi there,

I have a ListBox with > 100 items, at the same time I have a Frame which has multible CheckBoxes. The Q is:

How can I make the frame move up/down with whichever is selected from the listbox ??

I have this code:


Code:
Private Sub Form_Load()
Frame1.Left = List1.Left + List1.Width
Frame1.Top = List1.Top - 180
End sub

Private Sub List1_Click()
Frame1.Top = List1.ListIndex * 300
End Sub


The 2 problems i'm having are:

- The Listindex When it's (0) ??
- When selecting item > 20 , the Frame would be Hidden !?


Thanx for any help.

Scroll Selected Item To Top In ListBox Control
I have a multiple select list box control on an aspx page controlled by VB code. I only have enough real estate to show 5 items in the list at any one time, therefore, the list box contains more items than will show at any one time. When an items is selected, the OnSelectedIndexChanged event is fired which gathers the selected items for later processing and the aspx is refreshed. This all works fine with the following problem, the refresh of the aspx always shows the very top portion of the list in the list box control regardless of which items are selected. How do I force it to automatically scroll down to the first selected item in the list if this item is not in the topmost portion of the list? In PowerBuilder, I would just do a ScrollToTop and supply it with the index of the item I wanted it to scroll to. I cannot find any way to do that with VB. Any help would be greatly appreciated. Thanks in advance for your help.

Loading A Form When Item In Listbox Is Selected
Hi guys and gals.
  I want to be able to select a specific name in a listbox that will load a form with a flexgrid on it, which will have data from a table loaded into it. Now I can do all this if I have just 1 name in the list. I want to be able to click on any name and load a form with that names personal table. Thanks in advance.
Daz

How To Use Value Of Selected Item In Access 2000 Form Listbox
I have a listbox on a form in Access 2000. Using VBA, I run a search of files within a certain directory, and then display the results in the listbox. The items are added using the "Row Source" value in the listbox.

What I would like to do is enable the user to double-click one of the files in the list, and have the file open. I was trying to use the following code, but am unsure how to reference the selected file value:

-----
Dim strSelected As String
strSelected = ListBox1.???
Application.FollowHyperlink (strSelected)
-----

Any help would be appreciated!
Thanks in advance,
Malcolm

Populate ListBox Based On Item Selected In Combobox
Hi!

I really need a help in this. Here is my scenario:

1. I have an ms access database which has 2 different tables: Custom and Clinet.

2. I have a CustomID field in both Custom and Clinet data tables.

3. I have also a form Which has a combox and listbox. The combobox is populated from the Custom data table and the Listbox is populated from the Clinet data tables.

My problem is how can I filter the listbox based on the selected item in combobox. Or I would like the listbox shows only the datas that has the same CustomID as in the CustomID I selected in combobox.

Thanks a lot for any help or some code.

petk65

Simple Listbox Question - Removing Selected Item
Easy question for you all - how can I have the user click a button and have a select listbox item removed? I cannot seem to get this, as i always needs its index.
To rephase, I need to be able to tell what the index is of the selected item in a listbox, when the contents are changing (the user inputs the contents).
Any ideas would be great! Thanks!

Item Selected In Listbox Determines Variable To Fill
I know I'm missing something simple because I've written 1st grade code my procedure is too large to compile. I have an array of 7 list boxes. Each list box contains 80 numbers which correspond to a competitor. When the competitor is selected in the list box I need to add the value in the corresponding text box to their accumulated score. (See below a small sample)
Since I have done this 80 times for each listbox the code is too large to compile. What am I missing to shorten it?

Sub GetUserProsecution()

If lstMemberIDProsecution(0).Text = 1 Then intID1 = txtPCA.Text + intID1 Else
If lstMemberIDProsecution(0).Text = 2 Then intID2 = txtPCA.Text + intID2 Else
If lstMemberIDProsecution(0).Text = 3 Then intID3 = txtPCA.Text + intID3 Else
If lstMemberIDProsecution(0).Text = 4 Then intID4 = txtPCA.Text + intID4 Else
If lstMemberIDProsecution(0).Text = 5 Then intID5 = txtPCA.Text + intID5 Else
If lstMemberIDProsecution(0).Text = 6 Then intID6 = txtPCA.Text + intID6 Else
If lstMemberIDProsecution(0).Text = 7 Then intID7 = txtPCA.Text + intID7 Else

Copyright © 2005-08 www.BigResource.com, All rights reserved