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




Arrange ListBox Items


Hi,
I have a list box with a lot of names; I just want it when I click on command1 to arrange the names inside by alphabetical order….
Thx




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Arrange ListBox Items!
A VB6 project has 2 Forms, named Form1 & Form2. Both the Forms have a ListBox. When the project loads for the very first time, the ListBox in Form1 is empty. The ListBox in Form2 is populated with items from a text file, named Text.txt, when Form2 gets loaded everytime. All the items in Text.txt are sorted alphabetically from A to Z. Both the Forms have a OK CommandButton as well. Additionally, Form1 has 2 more CommandButtons - the first one when clicked opens Form2 & the second one is for users to remove any item from the ListBox in Form1.

When an item in the ListBox in Form2 is selected & the OK button is clicked, that item gets deleted from this ListBox & this item gets added to the ListBox in Form1. At the same time, a new text file, named Text2.txt, gets created which is populated with all the items existing in the ListBox in Form2.

Conversely when an item is removed from the ListBox in Form1, that item gets added to the ListBox in Form2 (but Form2 doesn't open). When the OK button in Form1 is clicked, a new text file, named Text1.txt, gets created which is populated with all the items existing in the ListBox in Form1.

When the 2 Forms get loaded next time, the Form1 ListBox gets populated with the items existing in Text1.txt & the Form2 ListBox gets populated with the items existing in Text2.txt.

The problem is in arranging the items in the 2 text files, Text1.txt & Text2.txt (& also in the 2 ListBoxes), alphabetically.

Assume that Text.txt has the following items:

Australia
Bahamas
Canada
Denmark
Egypt
Finland
Haiti
India
Jordan

I open Form2 (by clicking a CommandButton in Form1). The ListBox in Form2 gets populated with the above-mentioned items. Next I select Denmark from the Form2 ListBox & click the OK button. Denmark gets deleted from the Form2 ListBox & gets added to the Form1 ListBox. At the same time, Text2.txt gets created which is populated with all the items existing in the Form2 ListBox (which are the above-mentioned items excluding Denmark).

Next I again open Form2, select Bahamas from the ListBox & click the OK button. Bahamas gets deleted from the Form2 ListBox & it gets added to the Form1 ListBox. I again open Form2, select India from the ListBox & click the OK button. India gets deleted from the Form2 ListBox & it gets added to the Form1 ListBox.So the Form1 ListBox now looks like this:

Denmark
Bahamas
India

But the 3 items in the Form1 ListBox aren't sorted alphabetically from A to Z. So when the OK button is clicked in Form1, then Text1.txt gets created with the above 3 items (in that order). Similarly, when an item in the Form1 ListBox is deleted, that item gets added to the Form2 ListBox but here as well, the items in the Form2 ListBox aren't sorted alphabetically.

Now how do I sort the items in the 2 ListBoxes in an alphabetical manner when they get populated dynamically?

Re-arrange An Items In LISTVIEW?
Hi,

The app have a LISTVIEW with multi-columns in it, I want to let the user move the selected item up and down to whatever position they want to go.

Preferred to create two "UP" and "DOWN" button on the form, so the user just hightlighted the item in the listview then move it up and down.

No need to handle select multiple-items

Any simple will be great.

Thanks!

Re-arrange List Items
gd day gents.
This will be hard to explain with my bad english...

Is there any way to "re-arrange" the order of a lists items?
I would like them to be randomly re-arranged..

Simplest Way To Arrange My Listview Items
i have this listview that gives me weird Icons displays

try to Populate it

and then switch to Icon View

you will notice that there is a space on the left side of the Icons, there shouldnt be a space there, and the Icons should be on that particular space since i arranged the listview with autoleft

attached file is a sample program that is similar to my original program

i just wanted it to look like windows explorer


btw, im using VB6 sp6

Simple Way To Arrange My Listview Items
i have a listview that can display in 4 types of view, list and report view is good, but with smallicons and Icons i sometimes get these results:


as you can see, this is with smallicons, some 2nd column items overlap the 1st column, which is okay, what's not good is when 1st column items overlap 2nd column items



this problem I also encounter when smallicons and Icons view, notice the space on the left side (circled red).


thing is, sometimes i get desirable views, labels wrap, icons aligned, and no overlappings when changing views and or changing the items in the list

does anybody have work-around for this?
all i wanted is something that looks like windows explorer...
thanks

How Can You Arrange Items Alphabetically In A Listview?
That is, if the first column is arranged alphabetically, all the data in the other columns will be arranged properly too..


Code:
Apple Eat Tree
Dog Play Ball
Cat Meow Food


so when its arranged alphabetically, it appears as

Code:
Apple Eat Tree
Cat Meow Food
Dog Play Ball

Arrange Text In A ListBox?
Hello all,

I'll get to the point. Does anyone know how i go about arranging text in a
list box?

I am loading a name and number into a listbox from an array, using code
snippet below:

For s = 1 To amtOfRecords
lstSorted.AddItem (numArray(s) & " " &
nameArray(s))
Next s

I have used the series of spaces in between to seperate the name & number.
But the number field all seem out-of-line when they're printed into the
ListBox.

Can anyone help me fix this for them to be aligned?

Copying The Items From My Listbox To Another Listbox Not In My Program?[UNSOLVED]
Hey!
As you can see I want to copy the items from a listbox in my form into another program(wich i didnt made it, but the program is made with VB)
How can I do this?
P.S : There are two listboxes in the other app!

Thank you!!

I Want To Display Data In Two Columns In Listbox And Add Items In Listbox How Is It Possible In Vb 6.0
i want to display data in two columns in listbox and add items in listbox how is it possible in vb 6.0 ...?

I Want To Display Data In Two Columns In Listbox And Add Items In Listbox How Is It Possible
i want to display data in two columns in listbox and add items in listbox how is it possible ...?

Move Items From Listbox To Listbox
I have a form that contains 2 listboxes. When the form loads the first list box appears the users enter the information in to a text box and on enter that information is placed in the list. Below the list I have a command button the command buttons needs to be able to get the information from list one and be viewed in list 2. Here is the catcher though after the user enters the information the user will need to go back and select the ones needed to be moved. I have set the multiselect to true so that works but I need the ones selected to be moved to listbox2 on click.

Thaks in advance for any help you can provide.

How To Sent Listbox Items To Other Items?
I would like to know, how I can sent the listbox items from one listbox ("LIST1") to another listbox ("LIST2") and clear the selected items from list1?

Add More Items To A Listbox And Keep The Old Items
I have a value in a listbox. But I wanna add more items into the listbox and keep the old items. The new items should be added to the right side of the old values on the same row separated with VbTab.

Add Items To Listbox
I would like to Add Items to Multi-column Listbox. I am using MS-Access 2000. I tried the following code, but it still didn't work. Can you pls tell me where i might have gone wrong.


Code:
list1.Column(1, 1) = "abc"
list1.Column(2, 1) = "abc"
list1.Column(3, 1) = "abc"
list1.Column(4, 1) = "abc"

Too Many Items For Listbox?
Howdy,
It looks as though a listbox can only handle 32,576 or so items. Is there a way to increase this number, or at least a way around this. It seems that all the items will fit into the listbox, but when you try to reference something with an index larger than this, you will get an overflow or invalid property array index. I would like to still use a listbox, but anything that I can use to highlight the line (listbox1.selected(i) = true) would work.
Here is what I am doing. I have a list of commands, lets say 50,000. I don't know if it will be more, but I know it will occasionally be larger than 32,000. These are all commands to a machine. As each line gets executed, the machine tells me and so I increment the highlighted line to the next one. Thus, the listbox will increment what is selected as the machine gets done with commands. I also have a pause and a continue, so I use the listbox indes as a starting point for the continue. I hope that this will help someone to help me. Let me know if there is anything else I can do if the situation is not clear. Thanks in advance.
Stuart

Using ListBox Items.
Hi,

I was wondering if anyone could tell me how to extract an item from a listbox such that I can perform a check on it against a user inputted value

List =
Malta
Germany
Ireland
UK
USA
Scotland

i.e if list.item = inputted value then
...
else
...
end if

Here is my rubbish code:

If optAdd.Value = True Then
'Add a country
Dim Index, i As Integer
Dim CountryPresent As Boolean

Index = lstCountries.ListCount
'Determine if country is in list
For i = 1 To Index
If lstCountries.ItemData(Index) <> txtCountry.Text Then
CountryPresent = True
End If
Next
' If country is not in list, add
If CountryPresent <> True Then
lstCountries.AddItem txtCountry.Text
End If


Yes, it doesn't work. I would appreciate some tips and advice as to where I am going wrong. Is my logic fundamentally flawed or is it just lack of an understanding of VB?


Thanks,

WW.

Add Items Above In Listbox
Private Sub Form_Load()
List1.AddItem "apple"
List1.AddItem "banana"
List1.AddItem "grape"
End Sub


I want that to create a listbox that will look like this:
grape
banana
apple

instead of this:
apple
banana
grape

Is this possible? thanks

Help With ListBox Items
I have a ListBox with checkboxes on a print dialog form. I want to be able to check certain items in the listbox and have some info printed for each item that is checked.

On the first row of the listbox, I have "Everyone". If this item is clicked, I want the value of all of the other items in the list copied to the same value as the first one. This way, I can click on the first item to check or uncheck the entire list.

What's the best way code that?


Also......
Once the correct list items are check and unchecked, and the print button is clicked on, how do I go through the list and see which ones are checked? I'm just not sure which listbox properties I need to be working with.

Thanks for the help.
gs

New Items To Listbox
How would I add only new, non-repeated items to a list box?

Thanks Everyone! Most of my questions are answered before I even post them (through other posts and searched).

Gilmesh

Reunite Pangea!

Listbox Max Items ?
hello , got my listbox loaded with a very big file . +-7 meg

everything is visuable.

but when i use the list1.listcount it gives me 18345 but there are many many more items in the listbox.


is this a known issue ?

Listbox Add Items
I have listbox2 and listbox 3. All this is the multiselect.

After select the items in the listbox2, It will added the items into listbox3. So How I can remove the items selected in the listbox2 after added the items in the listbox3?


Code:

For i = 0 To List2.ListCount - 1 'select sheet
If List2.Selected(i) = True Then
List3.AddItem (List2.List(i))

End If
Next

Listbox Items
Alright, I have a list box with some items, but is there a way to make it so when they click a specific itm in the listbox, it would do an action...
Also, is there a way to get a time on a listbox? I tried with a timer, but it keeps adding one...

60,000 Items In Listbox
How can I list morethan 32768 items in a listbox? I need to show 60,000 items. Or is there any alternative to solve this problem (other than using another listbox in the same position of first and switching between the two)?

Thanks,
Jain

About Listbox Items - Can I Have...
Can I have several infos in the same item but only display the first
part of the info...

I mean:

If i loaded the info--> MyFileName , MyFilePath
into an listbox,how can i do it so that the listbox only display
MyFileName, but so that it also remembers the MyFilePath
so that if i EG doubleclicked the Item then it would MSGBOX both MyFileName and MyFilePath

Is that Possible?

(not interested in using DataBase to do this.. Is there something else than listbox i can use, to do that?

---NB---
I Need the same function as you find in Winamp.
Winamp only displays the filename, but it also remembers the path info! (in the playlist)
----------

Get Listbox Items
I am simply trying to get the listbox items.  The index returns are correct but the text never appears in my msgbox?  Any ideas?

here is the code i am using:


Dim y As Integer

             For y = 0 To lstdata.ListCount - 1
            
               MsgBox lstdata.Text
 
             Next y

Listbox Items
Is it possible to recognize an item in a listbox as something other than a string? Specifically, I have some listboxes containing dates and I need to be able to assign the value to a variable as a date and not a string. Is this possible or am I way off base?

thanks,

Andrew

Transfer Items Through Listbox
Hello again!
I have a problem with listbox code. I have the following code to copy data to another sheet, but I would like to transfer it, not copy. How could I delete transferred row from the source sheet.


Code:
Private Sub CommandButton1_Click()
Dim iListCount As Integer, iColCount As Integer
Dim iRow As Integer
Dim rStartCell As Range

'Set a range variable to the first cell to recieve our data
'Using "End(xlUp).Offset(1, 0)" _
will give us the cell below the last entry
Set rStartCell = Sheet2.Range("A65536").End(xlUp).Offset(1, 0)

'Loop as many times (less one) as there are entries in our list.
'We must start from zero to use this in the Selected Property.
For iListCount = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(iListCount) = True Then 'User has selected
ListBox1.Selected(iListCount) = False
iRow = iRow + 1
'Now loop as many times as there are columns in MyRange
For iColCount = 0 To Range("A1:K2000").Columns.Count - 1
'place the selected data into the table, starting from _
range Ax and moving across as many columns as there are _
in the range MyRange.
rStartCell.Cells(iRow, iColCount + 1).Value = _
ListBox1.List(iListCount, iColCount)
Next iColCount
End If
Next iListCount

Set rStartCell = Nothing

End Sub


Private Sub UserForm_Initialize()

EntryCount = 0

End Sub
And also can I assign some constant to every value in this row, For examlpe if I choose 3rd row in listbox, then A3 would be MyValue1, B3 MyValue2 etc.

Thank you in advance for your help,
Laura

Delete All Items In A Listbox?
How can I delete all items in a listbox?

Thanks in advance.

Select All Items In A Listbox
How can I select all the items in a listbox via click a button on a form?

I have tried and tried I just cannot get it!

Thanks in advance.

Numbering Listbox Items
How do you number Listbox items?

Like when you click on a button to add, it adds the object but the postion it is on the listbox.

For example:

I type in "Apple" and then it adds. " 1. Apple" And also, how do I make it sort by alpha. and also tells me what postion it is on the list.

If we take the apple example and then I add "Add" it will show

"1. Add
2. Apple"

- nhl4000

Swap Items In Listbox
hi everyone, i am having a little problem here with my program. here is the scnario.

I have a listbox and two command button labeled up and down
what i wanted to do is when i clicked on the up button the selected item on the listbox will go up one step like this

A
B
C - Selected Item

when I clicked on the up button here is what should happen

A
C - Selected Item
B

I know there is alitle swapping here but i don't know where to start.

Thanks and I apprecitae if anyone can help me

BTW im using VB6

Remove Listbox Items
Is it possible to remove items from listbox by giving item's name not it's index?
I mean if listbox has items Cat, Dog and Cow then what should I do if I want to remove item Dog, but not knowing what index it has?

How To Select Items From Listbox
Hey guys I have this assignment where i am to create a calculator as attached:

Basically I am to input the 2 inputs to be calculated into the 2 input boxes lst v1 and v2, and select from the lst Oper box the function I wish to perfrom for example +, -, / and * my question is, is how within the program do i make it so that the item selected by the user within the lstOper box is performed? i understand if it were a button but how can i get the program to understand that i have selected that particular function from the list either being a plus or minus?

ListBox Items Position
hello,
In a list box, I want the user to be able to drag the items and change there positions, u just click on any item and move your mouse downward and the item moves downward... same thing for moving upward...
any help?

Count ListBox Items
This should be an easy one. How do i display the ammount of items currently in a listbox in a textbox?
Im tired and i cant think of anything. Sorry its a stupid question.

Help Splitting Items In A Listbox
I need to split a listbox up by 7 items. My program will assign each split into filenames (split01, split02, etc). This part is already done, but I need to remove the items from the listbox and my code doesn't quite seem to work.


Code:
Private Sub SaveListTo(ByVal filename As String)
Dim intFNum As Integer, x As Long
intFNum = FreeFile
Open App.Path & "" & filename & ".txt" For Output As #intFNum
For x = 0 To 7
Print #intFNum, List1.List(x)
List1.RemoveItem List1.List(x)
Next
Close #intFNum
End Sub

Listbox Select Items
I have a listbox that presents 2 different numbers on each line of the listbox, they are related form a previous calculation and appended together with 5 blank spaces between the numbers so the user can tell them apart when they are scrolling down the list. I want to have the user click on one of these items, the 2 numbers, in the listbox, and display just one of the numbers.

Can I trim that particular variable in the listbox somehow after I've selected it? so only one of the numbers can be presented in another textbox.

Or better yet, can I have two different listboxes that are related somehow so when the user selects something on one box it automatically selects the related item on the same line in the other listbox. Then I won't have to append in the first place and will have better control over the variables.

Thanks

Adding Items To LISTBOX
I want the listbox in my form to display 3 strings.
How can I add these 3 strings to the listbox??
P.S. Don't thinkg Additem works for me...

Randomize Listbox Items?
I am really going to be asking you guys a lot of questions in the next couple of days... My VB final evaluation project is due on Monday and it heavily relies on databases which we barely covered in class. Therefore most of my worktime was spent trying to fix database problems and I only have until Sunday night to finish a project... my first problem that I need help with is how to randomize names that are in a listbox.

I have:

Code:
bSwitch = False
datLeague.Refresh

Do Until datLeague.Recordset.EOF
lstPlayerOne.Clear
lstPlayerTwo.Clear

If datLeague.Recordset!Division = "Expert" Then
If bSwitch = False Then
lstPlayerOne.AddItem datLeague.Recordset!Name
bSwitch = True
'datLeague.Recordset.MoveNext
ElseIf bSwitch = True Then
lstPlayerTwo.AddItem datLeague.Recordset!Name
bSwitch = False
'datLeague.Recordset.MoveNext
End If
End If
datLeague.Recordset.MoveNext
Loop
This is a league program, I only included 1/4 of the code here... the rest is identical, except with "Expert" being "Beginner", "Average", and "Advanced".

Right now it's just loading all the names already previously entered into the database into two seperate listboxes, but I need them to show up in a completely random order everytime the button that loads them is clicked and I have no idea how to do that. Please help! (Note that since it's a school project I have to use an older version of VB and Access)

Selecting Items From Listbox
i have a listbox full of items and i want to be able to select an item and have it delete itself from the listbox and send it's information to a variable. any ideas on how to do this?

Preselect Some Items In A Listbox
if i want to create a listbox with a list of items from an array. this much i know how to do, but i want to be able to make some of the items to be selected by default, the multiple selection property is set to multipleselectmulti, and so there could be more than one item i want to be selected defaultly. is there some easy way to do this?


-ravi

Adding Items To A Listbox
can anyone help,

i have a sub which is setting up a listbox from the contents of a recordset.
because the field names are not known nor do you know how many fields are returned, i am trying to truncate the listbox.additem string.
whoever below is what i have written but this does not work because it
is just adding the sql$ string and the & vbtab & are not being recognised as field seperators.

any ideas are much appriciated.

thanks

Private Sub cmdRun_Click()
Dim i As Integer
lstQuery.Col = 1
SQL$ = lstQuery.ColText
Set SQLRecs = Db.OpenRecordset(SQL$, dbOpenSnapshot)
With SQLRecs
i = 0
Do Until i = .Fields.Count
lstRecords.Col = i
lstRecords.ColTitle = .Fields(i).Name
lstRecords.ColScale = mhColSmTwips
lstRecords.ColWidth = 3000
i = i + 1
Loop
.MoveFirst
SQL$ = ""
Do Until .EOF
i = 0
Do Until i = .Fields.Count
If IsNull(.Fields(i)) = True Then
SQL$ = SQL$ & " "
Else
SQL$ = SQL$ & .Fields(i)
End If
i = i + 1
If i <> .Fields.Count Then
SQL$ = SQL$ & " & vbtab & "
End If
Loop
lstRecords.AddItem SQL$
.MoveNext
Loop
End With

End Sub

Inserting Items In A Listbox
I would like to know how to insert an item to a listbox at a certain line. For example if a listbox was filled with data like this;

lstBox.Additem "First"
lstBox.Additem "Second"
lstBox.Additem "Third"

Would anyone know how to make an entry between the second and third entries, pushing the third entry down to the fourth position and making a new entry?

Moving Items Up And Down In A Listbox
I just solved this question that I've had for a while.

Thought I'd share the code.

http://cornempire.newezone.com/resou...e/listmove.htm

Delete Same Items From Listbox
I searched the forum couldn't find anything though.

Due to my poor coding, i have items that are the same value "AAA" that are beign added to a listbox twice. I don't know how to fix it, so i was wondering of another way.

How could i scan the listbox and find anything that is entered twice and delete all of them from the listbox except 1 of them?


Here is the code

Code:
recsize = Len(atrader)

Open App.Path & " rade.dat" For Random As 1 Len = recsize

recnum = LOF(1) / recsize

Do Until x = recnum
x = x + 1

Get #1, x, atrader

var1 = atrader.RefNum
var2 = atrader.NickName

Open App.Path & "Goods.dat" For Input As 2

Do Until EOF(2)
Line Input #2, checkns
nsfound = Left(checkns, 1)

If nsfound = "R" And Mid(checkns, 2, 10) = var1 Then
lstNames.AddItem var2



End If

Loop

Close #2

Loop

Close #1

What happens is i have a file with Customer details and a file of what they ordered.
In the order file it saves as "R0000000001" for one person's order, "R0000000002" for the 2nd person and so on. "R0000000001" identifies which customer ordered. NOT what they ordered. If they order 2 items, when i run my program it adds the customer twice to the listbox.

I was thinking about putting code to check if var2 exists in the listbox before it adds. but i wasnt sure how.

Any help would be great

cheers, Juve

Listbox Items Problem
I made a swear list for my speech program and stuck them into a list box named lstSwears. When I execute a For...Next loop to check for swear words, it crashes. Here's the code for that bit:


Code:

Dim I As Integer
Dim Swear As String
Dim CurSwear As String
If SwearFilter = True Then
MsgBox("SwearFilter = True")
For I = 0 To lstSwears.Items.Count
CurSwear = lstSwears.Items.Item(I) ' It stops here
Swear = CurSwear
txtSay.Text = Replace(txtSay.Text, Swear, "beep")
Next
End If
ttsSay.Speak(txtSay.Text)
lstSaid.Items.Add(txtSay.Text)
It says:
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from string "" to type 'Integer' is not valid.

How Can U Tell If Items In Listbox Have Changed
I have a listbox that contains items a user has added to it.
The items are saved in a file called 'listitems' when the user clicks the cmdsave button.
If the user decides to close the application before saving, I want a message to appear that asks the user if they want save before closing, but i only want to prompt the user if the listbox has been changed since the last time the user clicked 'save'.
I thought the listbox would have a 'change' event but it doesnt. So how can i tell if the contents of a listbox have changed.
Thanx
trin

Formatting Items In A Listbox
I am using this code to store Items in a listbox.

TotalList = Text1.Text & vbTab & Text2.Text & vbTab & Text3.Text
List1.AddItem TotalList

The first and last string are always the same size in length. The problem is that depending on the size of the 2nd string the colums in the listbox don't line up evenly.
Any ideas of how to do this better is much appriciated!

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