Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView.SortOrder

Status
Not open for further replies.

ousoonerjoe

Programmer
Jun 12, 2007
925
US
When attempting to remember the grid Sort Column and Sort Order to refresh the grid and return the user to the line they were at, the SortOrder does not seem to be playing well with others. When specifically defined as with the Select Case, the value reports correctly, but when expressed directly, it returns an error (The value of argument 'direction' (2) is invalid for Enum type 'ListSortDirection'.
Parameter name: direction). What is missing here? There should be no difference between the two.
Code:
	Dim SortOrder As System.ComponentModel.ListSortDirection
	Select Case .dgTickets.SortOrder
	    Case Windows.Forms.SortOrder.Ascending
	        SortOrder = System.ComponentModel.ListSortDirection.Ascending
	    Case Windows.Forms.SortOrder.Descending
	        SortOrder = System.ComponentModel.ListSortDirection.Descending
	    Case Windows.Forms.SortOrder.None
	        SortOrder = System.ComponentModel.ListSortDirection.Ascending
	End Select
	SortOrder = .dgTickets.SortOrder
	SortCol = .dgTickets.SortedColumn
	.LoadGrid()
	Application.DoEvents()
	If Not SortCol Is Nothing Then
	    SortCol = .dgTickets.Columns(SortCol.Index)
	    .dgTickets.Sort(SortCol, SortOrder)
	End If

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
Never mind.

I saw the difference as the message was posting.

DataGridView.SortOrder returns a value of Windows.Forms.SortOrder

versus

DataGridView.Sort() is looking for a value of System.ComponentModel.ListSortDirection

How irritating that the same control uses two different references for sorting.

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top