467,894 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Error in listview sorting vb.net 2005 enterprise edition

hi all,
I want to sort the colum when clicks the columnheader using vb.net 2005 .But i receive the following error
"Error 1 Overload resolution failed because no accessible 'New' accepts this number of arguments. "

and my code is
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
  3. If e.Column <> sortColumn Then 
  4. sortColumn = e.Column
  5. ListView1.Sorting = SortOrder.Ascending ' asc by default 
  6.  
  7. If ListView1.Sorting = SortOrder.Ascending Then
  8. ListView1.Sorting = SortOrder.Descending
  9. Else
  10. ListView1.Sorting = SortOrder.Ascending
  11. End If
  12.  
  13. ListView1.Sort()
  14. Dim sorted As New classSorter(e.Column, ListView1.Sorting)
  15. ListView1.ListViewItemSorter = sorted
  16.  
  17. End If
  18.  
  19. End Sub
  20.  
  21. Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
  22.  
  23. End Sub
  24. End Class
  25.  
  26. Public Class classSorter
  27. Implements IComparer
  28.  
  29. Private col As Integer ' column to sort 
  30. Private order As SortOrder ' asc or desc 
  31.  
  32. Public Sub New()
  33. col = 0 ' sort first col by default in ascending order 
  34. order = SortOrder.Ascending
  35. End Sub
  36.  
  37. ' c-tor that receives column to sort and in which order 
  38. Public Sub New(ByVal aColumn As Integer, ByVal order As SortOrder, ByVal aForm As Form)
  39. col = aColumn
  40. Me.order = order
  41. End Sub
  42.  
  43. ' method to compare two objects (list view items) 
  44. Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
  45.  
  46. Dim returnVal As Integer = -1
  47.  
  48. Dim xItem As System.Windows.Forms.ListViewItem = x
  49. Dim yItem As System.Windows.Forms.ListViewItem = y
  50.  
  51. Select Case col
  52. Case 0 ' in this case 0th column holds numerics 
  53. ' sort numeric values 
  54. Dim blnCompare As Boolean
  55.  
  56. blnCompare = Val(xItem.SubItems(col).Text) > Val(yItem.SubItems(col).Text)
  57.  
  58. If blnCompare Then
  59. returnVal = 1
  60. Else
  61. returnVal = -1
  62. End If
  63.  
  64. Case 1 ' in this case 1th column holds strings 
  65. ' sort strings 
  66. returnVal = [String].Compare(CType(x, ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
  67.  
  68. Case 2 '' in this case 2nd column holds datetime vals 
  69. ' sort date time values 
  70. returnVal = DateTime.Compare(CDate(xItem.SubItems(col).Text), CDate(yItem.SubItems(col).Text))
  71.  
  72. Case 3
  73. returnVal = DateTime.Compare(CDate(xItem.SubItems(col).Text), CDate(yItem.SubItems(col).Text))
  74.  
  75. Case 4 '' in this case 0th column holds numerics 
  76. ' sort numeric values 
  77. Dim blnCompare As Boolean
  78.  
  79. blnCompare = Val(xItem.SubItems(col).Text) > Val(yItem.SubItems(col).Text)
  80.  
  81. If blnCompare Then
  82. returnVal = 1
  83. Else
  84. returnVal = -1
  85. End If
  86.  
  87. Case Else
  88.  
  89. End Select
  90.  
  91. ' is sort order descending 
  92. If order = SortOrder.Descending Then
  93. ' ivert the value returned by string.compare. 
  94. returnVal *= -1
  95. End If
  96.  
  97. Return returnVal
  98. End Function
  99.  
please help me...i need the solution very urgent.....
Jul 17 '08 #1
  • viewed: 1510
Share:
4 Replies
DrBunchman
Expert 512MB
Hi rajtalent,

I've editied your post above to surround your code with [code] tags - please use the # button in the edit window to do so in future.

Which line are you receiving the error on?

Dr B
Jul 17 '08 #2
Hi rajtalent,

I've editied your post above to surround your code with [code] tags - please use the # button in the edit window to do so in future.

Which line are you receiving the error on?

Dr B

Hi Dr B
Sorry for inconvenience...I got an error in line no.13..."sorted" highlighted as error..please give me solution
Jul 17 '08 #3
DrBunchman
Expert 512MB
Hi rajtalent,

Have you been able to fix your problem yet?

Dr B
Jul 22 '08 #4
Curtis Rutland
Expert 2GB
Well, you've defined two constructors (the "New" subs): one with no arguments, and one with three. On line thirteen, you are trying to instantiate a new object with only two arguments:

line 31 constructor with no arguments
Expand|Select|Wrap|Line Numbers
  1. Public Sub New()
  2.     col = 0 ' sort first col by default in ascending order
  3.     order = SortOrder.Ascending
  4. End Sub
  5.  
' line 37 constructor with three arguments
Expand|Select|Wrap|Line Numbers
  1. Public Sub New(ByVal aColumn As Integer, ByVal order As SortOrder, ByVal aForm As Form)
  2.     col = aColumn
  3.     Me.order = order
  4. End Sub
  5.  
'line 13, where you instantiate with only two arguments:
Expand|Select|Wrap|Line Numbers
  1. Dim sorted As New classSorter(e.Column, ListView1.Sorting)
  2.  
So either you made a mistake in your constructor, or in your declaration.
Jul 22 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Keith | last post: by
4 posts views Thread by mcwooq | last post: by
6 posts views Thread by Dave | last post: by
42 posts views Thread by Paul | last post: by
2 posts views Thread by thersitz | last post: by
4 posts views Thread by =?Utf-8?B?ZGF2aWQ=?= | last post: by
14 posts views Thread by Guillermo_Lopez | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.