borderAndreaVB free resources for Visual Basic developersborder
AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2017 Andrea Tincani
:: Sort data in MS Flex grid by clicking the column

Author  

Sujatha G

Language  

VB5, VB6

Operating Systems  

Windows 95,98,NT
Tip
Option Explicit

'Imagine that data has retrived in The MS Flex Grid.
'How on clicking in the list view we can sort the data like wise we can do 
'with the flex grid also.
'          
'          the property used is Mousecol of Flexgrid.
'          
'          for the code to work place a Flex grid on the form
'          
'Code:
          
Private Sub Form_Load()
    Dim Str As String
    Dim i As Integer
    Dim j As Integer

    i = 0: j = 0
    MSFlexGrid1.Rows = 1
    Randomize
    For i = 1 To Int(Rnd() * 10) + 1
        Str = ""
        For j = 1 To 10
            Str = Str & Chr(65 + Int(Rnd() * 26))
        Next
        MSFlexGrid1.AddItem Int(Rnd() * 100) & vbTab & Str
    Next
End Sub

Private Sub MSFlexGrid1_Click()
    Call FlexSort("A")
End Sub

Private Sub MSFlexGrid1_DblClick()
    Call FlexSort("D")
End Sub

Sub FlexSort(Mode As String)
    If MSFlexGrid1.Row = 1 Then
       If MSFlexGrid1.MouseCol = 0 Then
            MSFlexGrid1.Col = 0
            If Mode = "A" Then
                MSFlexGrid1.Sort = flexSortNumericAscending
            Else
                MSFlexGrid1.Sort = flexSortNumericDescending
            End If
        ElseIf MSFlexGrid1.MouseCol = 1 Then
            MSFlexGrid1.Col = 1
            If Mode = "A" Then
                MSFlexGrid1.Sort = flexSortStringAscending
            Else
                MSFlexGrid1.Sort = flexSortStringDescending
            End If
        End If
    End If
End Sub
:: Navigation

Home

Database Management

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 05-07-2006 GRID - Free, spreadsheet style grid by zarkorgon
icon 05-07-2006 GRID - Free, spreadsheet style grid by zarkorgon
icon 12-02-2005 beginer question by panik!
icon 06-10-2004 Re: Formatted cells in flexgrid by gandalf12
icon 05-10-2004 Formatted cells in flexgrid by gandalf12
borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2017 Andrea Tincaniborder