This is a generally used usercontrol so that would be difficult unless I
required the form containing the control to do something to help.
Can't I get the type in the method somehow?
Thanks
"Carlos J. Quintero [.NET MVP]" <carlosq@NOSPAMsogecable.com> wrote in
message news:O$yJbPveFHA.2180@TK2MSFTNGP12.phx.gbl...[color=blue]
> Can´t you know in advance which is the data type of each column? If not
> then you have to guess it, but I would do that before comparing, that is,
> take the first listitem, guess if the column contains date or integer and
> then call a different comparer for each case.
>
> --
> Best regards,
>
> Carlos J. Quintero
>
> MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
> You can code, design and document much faster.
> Free resources for add-in developers:
>
http://www.mztools.com
>
> " **Developer**" <REMOVEdeveloper@a-znet.com> escribió en el mensaje
> news:emKtsqqeFHA.228@TK2MSFTNGP12.phx.gbl...[color=green]
>>I need to sort the columns of a ListView.
>>
>> Some columns contain dates and others contain integers.
>>
>> What I did once before is in the Compare method I tried date and if that
>> failed I did Integer.
>>
>> Seems kinda not nice - is there a better way?
>>
>> Thanks
>> Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
>> Implements IComparer.Compare
>>
>> -snip
>>
>> ''Cast the objects to be compared to ListViewItem objects.
>>
>> lListviewX = CType(x, ListViewItem)
>>
>> lListviewY = CType(y, ListViewItem)
>>
>> Try
>>
>> 'Parse the two objects passed as a parameter as a DateTime.
>>
>> Dim lFirstDate As System.DateTime =
>> DateTime.Parse(lListviewX.SubItems(mColumnToSort). Text)
>>
>> Dim lSecondDate As System.DateTime =
>> DateTime.Parse(lListviewY.SubItems(mColumnToSort). Text)
>>
>> 'Compare the two dates.
>>
>> lCompareResult = DateTime.Compare(lFirstDate, lSecondDate)
>>
>> ' Catch
>>
>> 'If neither compared object has a valid date format compare the two items
>> as a string
>>
>> lCompareResult =
>> mInsensitiveCompare.Compare(lListviewX.SubItems(mC olumnToSort).Text,
>> lListviewY.SubItems(mColumnToSort).Text) 'Or can do this
>>
>> End Try
>>
>>
>>[/color]
>
>[/color]