|
-
Oct 28th, 2009, 11:13 AM
#1
Thread Starter
Junior Member
Sorting Items In A TxtBx by Alphabetical Order ?
Hi All,
I have created a program that when a user selects a button, an input box is displayed to type in, for instance a name, when clicked ''OK'' the name goes into a textbox, how can i program it so that the contents of that textbox is automatically sorted into Alphabetical order according to the first to the first letter ?
Can this be achieved ?
Kind regards. 
THink this should have been posted in VB.NET forums, sorry.
Last edited by SWDT; Oct 28th, 2009 at 11:17 AM.
-
Oct 28th, 2009, 11:32 AM
#2
Re: Sorting Items In A TxtBx by Alphabetical Order ?
Put them in a ListBox instead of a textbox.
Sorting a listbox can be done simply by setting a property.
-
Oct 28th, 2009, 11:41 AM
#3
Re: Sorting Items In A TxtBx by Alphabetical Order ?
One more way to do it is export the text from the textbox to array and then sort it. Once sorted, export it back to textbox....
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 28th, 2009, 11:46 AM
#4
Thread Starter
Junior Member
Re: Sorting Items In A TxtBx by Alphabetical Order ?
Thanks chap - the issue I'm now having is that the text isn't going into the Listbox where as it was with the Textbox. What happens is a user click on the ''Create contact'' button where an inputbox displays, they enter a name and click ok, the name then appeared in the textbox, however changing it to a listbox and also moding the code to direct the text to the listbox, its no longer working and the text isn't displaying.
Is that a result of it being a listbox and not a textbox ?
Kind regards.
-
Oct 28th, 2009, 12:20 PM
#5
Hyperactive Member
Re: Sorting Items In A TxtBx by Alphabetical Order ?
Not sure what you are asking but you just need to forget the textbox, use a listbox as suggested with a simple bit of code similar to this.
Code:
Dim Response As String = InputBox("Enter Contact Name", "Create Contact")
If Response <> String.Empty Then
ListBox1.Items.Add(Response)
End If
-
Oct 28th, 2009, 12:24 PM
#6
Thread Starter
Junior Member
Re: Sorting Items In A TxtBx by Alphabetical Order ?
Thanks for that works a treat, I know I'm talking about the Textbox, however another feature that it was able to do was to save the text inside the textbox into a .TXT or whatever, I've noticed that I cannot save the items that are in the listbox the same way, is that possible. Here is the save code that I'm using:
Code:
Dim Save As New SaveFileDialog()
Dim myStreamWriter As System.IO.StreamWriter
Save.Filter = "Text[*.DOOS*]|*.DOOS|All File[*.*]|*.*"
Save.CheckFileExists = False
Save.Title = "Save File"
Save.ShowDialog(Me)
Try
myStreamWriter = System.IO.File.AppendText(Save.FileName)
myStreamWriter.Write(ListBox1.Text)
myStreamWriter.Flush()
Catch ex As Exception
End Try
Many thanks to all help so far.
-
Oct 28th, 2009, 12:35 PM
#7
Re: Sorting Items In A TxtBx by Alphabetical Order ?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 28th, 2009, 12:36 PM
#8
Thread Starter
Junior Member
Re: Sorting Items In A TxtBx by Alphabetical Order ?
Ah apologies missed that - I can give that a go, is that easy enough to accomplish ?
-
Oct 28th, 2009, 12:43 PM
#9
Re: Sorting Items In A TxtBx by Alphabetical Order ?
It is ...
Give it try...
If you get stuck then simply post the code that you have tried and we will definitely help
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 28th, 2009, 12:56 PM
#10
Re: Sorting Items In A TxtBx by Alphabetical Order ?
Here is one simple way to do it using LINQ.
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sortedText = From t In Split(TextBox1.Text, vbCrLf) Order By t TextBox1.Text = Join(sortedText.ToArray, vbCrLf) End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|