Showing posts with label link. Show all posts
Showing posts with label link. Show all posts

Monday, 13 October 2014

VB.NET: How to sort listview by clicked column

Ok, I claim no credit for this whatsoever, but just in case Fryan Valdez ever takes down his blog I'll repost the information in his blog post here:

Please click through to read the original blog, I provide a copy of it here purely for my information and future reference

http://www.fryan0911.com/2009/05/vbnet-how-to-sort-listview-by-clicked.html

To make your ListView application capable of column sorting, follow these steps:

1. On your existing project, add a new class with following code:

Public Class clsListviewSorter ' Implements a comparer
    Implements IComparer
    Private m_ColumnNumber As Integer
    Private m_SortOrder As SortOrder
    Public Sub New(ByVal column_number As Integer, ByVal sort_order As SortOrder)
        m_ColumnNumber = column_number
        m_SortOrder = sort_order
    End Sub
    ' Compare the items in the appropriate column
    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
        Dim item_x As ListViewItem = DirectCast(x, ListViewItem)
        Dim item_y As ListViewItem = DirectCast(y, ListViewItem)
        ' Get the sub-item values.
        Dim string_x As String
        If item_x.SubItems.Count <= m_ColumnNumber Then
            string_x = ""
        Else
            string_x = item_x.SubItems(m_ColumnNumber).Text
        End If
        Dim string_y As String
        If item_y.SubItems.Count <= m_ColumnNumber Then
            string_y = ""
        Else
            string_y = item_y.SubItems(m_ColumnNumber).Text
        End If
        ' Compare them.
        If m_SortOrder = SortOrder.Ascending Then
            If IsNumeric(string_x) And IsNumeric(string_y) Then
                Return Val(string_x).CompareTo(Val(string_y))
            ElseIf IsDate(string_x) And IsDate(string_y) Then
                Return DateTime.Parse(string_x).CompareTo(DateTime.Parse(string_y))
            Else
                Return String.Compare(string_x, string_y)
            End If
        Else
            If IsNumeric(string_x) And IsNumeric(string_y) Then
                Return Val(string_y).CompareTo(Val(string_x))
            ElseIf IsDate(string_x) And IsDate(string_y) Then
                Return DateTime.Parse(string_y).CompareTo(DateTime.Parse(string_x))
            Else
                Return String.Compare(string_y, string_x)
            End If
        End If
    End Function
End Class
2. Declare a private variable on the form where the listview you want to be sorted is located.

Private m_SortingColumn As ColumnHeader

3. Then on the listview's ColumnClick event, add the following code

Private Sub ListView1_ColumnClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
        ' Get the new sorting column.
        Dim new_sorting_column As ColumnHeader = ListView1.Columns(e.Column)
        ' Figure out the new sorting order.
        Dim sort_order As System.Windows.Forms.SortOrder
        If m_SortingColumn Is Nothing Then
            ' New column. Sort ascending.
            sort_order = SortOrder.Ascending
        Else ' See if this is the same column.
            If new_sorting_column.Equals(m_SortingColumn) Then
                ' Same column. Switch the sort order.
                If m_SortingColumn.Text.StartsWith("> ") Then
                    sort_order = SortOrder.Descending
                Else
                    sort_order = SortOrder.Ascending
                End If
            Else
                ' New column. Sort ascending.
                sort_order = SortOrder.Ascending
            End If
            ' Remove the old sort indicator.
            m_SortingColumn.Text = m_SortingColumn.Text.Substring(2)
        End If
        ' Display the new sort order.
        m_SortingColumn = new_sorting_column
        If sort_order = SortOrder.Ascending Then
            m_SortingColumn.Text = "> " & m_SortingColumn.Text
        Else
            m_SortingColumn.Text = "< " & m_SortingColumn.Text
        End If
        ' Create a comparer.
        ListView1.ListViewItemSorter = New clsListviewSorter(e.Column, sort_order)
        ' Sort.
        ListView1.Sort()
    End Sub





Thursday, 10 February 2011

PHP IIS Got a whole lost easier

I can't remember if I’ve ever blogged about my problems setting PHP up on Windows under IIS, it can be a real headache... sometimes it works as per the documentation, other times (even on a clean server) it doesn't and I end up messing around with all kinds of settings and NTFS permissions, after several system reboots things finally start to work.

Recently I’ve been working on a project that involves using PHP and MSSQL (something I've not done before) it looks like php_mssql.dll is now history (up to PHP v5.2) the latest version of PHP uses a slightly different dll.

To my relief my latest PHP installation was a breeze, fire up the URL below, check all the stuff you want it to install and off it goes, all configured, all working (I wonder what the security is like)

http://www.microsoft.com/web/Downloads/platform.aspx

Wednesday, 19 January 2011

Online document conversion

I needed to convert a PDF document to an image today (didn't want to screen dump it due to resolution loss) after finding 2 or 3 services that boasted they could do the job 'online' and for 'free' (all 3 of which failed or couldn't handle a PDF as large as 1MB) I came across Zamzar. This website can handle a lot of common file conversions (e.g. mov to mpeg e.t.c.) It also features a YouTube video ripper (that could come in handy)

Check it out at http://www.zamzar.com/

Monday, 17 January 2011

Working with PDF’s


Occasionally I get asked to edit and amend some PDF documents, we only have 2 full Adobe Acrobat licenses on site and I don’t have access to one. I can create PDF documents pretty easily from Word and Excel 2007 by using a Microsoft Office Add-in (available here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=4d951911-3e7e-4ae6-b059-a2e79ed87041&displaylang=en) I can also produce PDF documents from any application that allows you to print by using CutePDF, which installs itself as a printer (available here: http://www.cutepdf.com/)

I few years ago I needed to actually reorder and edit some documents I found the PDF Toolkit Builder (PDFTK) immensely helpful as it allows you to collate and / or split existing PDF documents (you can also stamp and even rotate existing documents) check out PDFTK Builder (available here: http://portableapps.com/apps/office/pdftk_builder_portable)

Friday, 27 November 2009

PXE Boot solution

WDS Uninstalled, it’s a good product and I can see its benefits however it doesn’t do what I’m after. Luckily I stumbled across this website http://winner.windowsdream.com/

WINNER (Windows Is Not Necessary for Everyone's RIS) took a little work to get up and running, however the website does have blow by blow instructions

Tuesday, 20 October 2009

CSS Help

I was amending some CSS files while doing some development work when I came across the following website http://www.somacon.com/ it’s a blog by Shailesh N. Humbad. On his website are lots of useful articles for web development, close to the bottom of his blog are links for several useful CSS related tools he has developed, they are worth checking out

Tuesday, 6 October 2009

http://anonymouse.org/

I came across this website years ago http://anonymouse.org/ It was useful for (at the time) getting around work or school firewalls, now however I find it useful for checking public DNS has updated correctly.