5 Replies - 5204 Views - Last Post: 29 January 2010 - 01:44 PM Rate Topic: -----

#1 mepalival  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-January 10

Sort Textbox Data

Post icon  Posted 29 January 2010 - 06:51 AM

There is a Some Problem with Sort Data in Textbox with btncmd_click in VS2008

I have Data in textbox like this

Quote


I want to Sort Data to 0-9, A-z Like this

Quote



Can Any one guide me?

Thanks in Advance !!!

Is This A Good Question/Topic? 0
  • +

Replies To: Sort Textbox Data

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Sort Textbox Data

Posted 29 January 2010 - 08:19 AM

Read all the lines in textbox to string array and then use Array.Sort() method to sort that array. Then use for loop to iterate through the sorted array and write its' content to the textbox.
Was This Post Helpful? 1
  • +
  • -

#3 T.Jackson  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 97
  • Joined: 27-January 10

Re: Sort Textbox Data

Posted 29 January 2010 - 08:44 AM

View Postjanne_panne, on 29 Jan, 2010 - 07:19 AM, said:

Read all the lines in textbox to string array and then use Array.Sort() method to sort that array. Then use for loop to iterate through the sorted array and write its' content to the textbox.


Yeah, I think that it is best that you all shake n' RUN like hell with that approach.

It is perfectly coherent in all regards.

Thumbs up with that algorithm (a step-by-step solution to a problem)

Trent Jackson
Was This Post Helpful? 0
  • +
  • -

#4 mepalival  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-January 10

Re: Sort Textbox Data

Posted 29 January 2010 - 11:47 AM

Can anybody Give me a Examples ?
Was This Post Helpful? 0
  • +
  • -

#5 AlphaBlueTech  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 22-October 08

Re: Sort Textbox Data

Posted 29 January 2010 - 12:05 PM

This sounds like a homework project and more than likely nobody will offer up examples without you at least attempting it for yourself.
Was This Post Helpful? 0
  • +
  • -

#6 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Sort Textbox Data

Posted 29 January 2010 - 01:44 PM

Here is a sorting sample:

				''' <summary>
	''' A function that sorts the string lines from a TextBox control.
	''' </summary>
	''' <param name="textBox">The TextBox control containing the values to be sorted.</param>
	''' <param name="size">The size of the array. Should be the number of lines in the TextBox control.</param>
	''' <returns>items - Array of string</returns>
	''' <remarks></remarks>
	Private Function SortData(ByVal textBox As TextBox, ByVal size As Int32) As String()
		' The array that contains the initial set of items (not sorted)
		' The size is decresed by 1 unit because the array starts indexing from 0
		Dim items(size - 1) As String

		' Verify that the specified size is exactly the number of lines
		' to be sorted in the TextBox control.
		If size <> textBox.Lines.Count Then
			Throw New ArgumentOutOfRangeException
		Else
			For i = 0 To textBox.Lines.Count - 1
				items(i) = textBox.Lines(i)
			Next

			Array.Sort(items)
		End If
		Return items
	End Function



The function is quite easy to understand, just make sure to pass the correct size. You can just use TextBox1.Lines.Count for that parameter to avoid the process of manual line counting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1