ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 3 5

7 ѹҤ ..2549
90 Users On-Line.
Visitors - Page views
 8 9 7 3 8 7 8
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ҧԴ (MS Flex Grid) ... ͹èѴ§㹡ʴ MS FlexGrid

Category »  VB 6/VB.Net
: Webmaster 20/3/2552   : 01:09
(ҹ : 19799) 
ҡ͹Ǣͧͧ ҧԴ (MS Flex Grid) ... ҵ͹ͧͧ "Թҡ" ա Ǣ¤Ѻͧ ... èѴ§㹵ҧԴ ѧ鹻繹ҡͧ件֧äº Header 蹡Դ Sort (§) Method (Ը) ѡ (Column) ҡꡤáѴ§ҡҡ ͤա駡§ҡҡҹ ѡɳй÷ӧҹẺ¡ Toggle Ѻ÷ӧҹͧѺ ... ͧ ... ¹鴹ҹͧ 10 շ Ѩغѹѧ㹡ö·ʹ ʺó Ѻҧʺ ... й кǹäԴ-ԸդԴ 㹡ѭա˹觵ҧ ... ҹԧ
кǹäԴ ...
  • Դ˵ءó MouseDown ŧ价 MS FlexGrid
  • Ǩͺ繡äŧ价 Column Header ... ǤԴ ҡ˹觡 ԡѴ y (ǵ) ͧԹ٧ͧá Ф͡ä͡ Header ... 55555+
  • кѡԴä ... öѴ§çѡͧ
  • Ǩͺ繡äẺ ... Sort Method (Ըա) Ҫ㹡èѴ§ Ѻ÷ӧҹ
    • SortOrder = 1 èѴ§ҡҡ (Ascending)
    • SortOrder = 2 èѴ§ҡҡҹ (Descending)
ǹŴ
ǹŴ Source Code Ѻ MS Visual Basic 6.0 - Service Pack 6
 ǹŴ Visual Basic 6.0 SP5: Run-Time Redistribution Pack
 ǹŴ Microsoft Data Access Object (MDAC) Jet 4.0 Update
 ǹŴ Microsoft Visual Basic Service Pack 6

ҧԴ (MS Flex Grid) ... VB 6.0
ҹẺ Text File MS FlexGrid MS Visual Basic 6.0
ҧԴ (MS Flex Grid) ... ͹ Wheel Mouse MS FlexGrid
ҧԴ (MS Flex Grid) ... ͹ MS FlexGrid شȨ
鹡кǹ÷ӧҹ

Projects --> Component ...


Design Time


Run Time
Ҵ鴡ѹ ...

Option Explicit

' 纤㹡èѴ§
' SortOrder = 1  èѴ§ҡҡ (Ascending)
' SortOrder = 2  èѴ§ҡҡҹ (Descending)
Dim SortOrder As Byte

Private Sub Form_Load()
    Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
    Call SetupfgData
    Call DisplayfgData
    
    ' ˹
    SortOrder = 0
End Sub

' 駤Ҥسѵ (Properties) ҧѺ MS FlexGrid Ẻ Run - Time
Sub SetupfgData()
    With fgData
        .Clear
        '  Header 1 
        .FixedRows = 1
        .FixedCols = 0
        ' ᶺʧǵǹ͹ͧ
        .SelectionMode = flexSelectionByRow
        ' 駤Ҥ٧شͧ
        .RowHeightMin = 285
        '  - ¤ҧͧѡ
        .AllowUserResizing = flexResizeNone
        
        ' ˹ 5 ѡ
        .Cols = 5
        ' ˹ 1  (Ѻ Header)
        .Rows = 1
        
        ' ˹ Header
        .TextMatrix(0, 0) = "ProductPK" ' Ҥë͹ Primary Key ѡ 0 - DataBase
        .TextMatrix(0, 1) = "ӴѺ"
        .TextMatrix(0, 2) = "Թ"
        .TextMatrix(0, 3) = "ѹѺԹ"
        .TextMatrix(0, 4) = "Ҥ"
        
        ' ѡ 2 (Թ) ʴ˹觪Դ
        .ColAlignment(2) = vbLeftJustify
        
        .ColWidth(0) = 0
        .ColWidth(1) = 650
        .ColWidth(2) = 1400
        .ColWidth(3) = 2200
        .ColWidth(4) = 2150
    End With
End Sub

' ŵҧŧ MS FlexGrid
Sub DisplayfgData()
Dim i As Integer
    
    fgData.Rows = 6
    For i = 1 To 5
        With fgData
            .TextMatrix(i, 0) = i
            .TextMatrix(i, 1) = i
            .TextMatrix(i, 2) = Right$("0000000" & i, 7)
            .TextMatrix(i, 3) = FormatDateTime(Now() + i, vbShortDate)
            .TextMatrix(i, 4) = 6 - i
        End With
    Next
    
' ѹਵ¡ͧ 繼ŢͧèѴ§ҧѴਹ
fgData.TextMatrix(2, 3) = "05/02/52"
fgData.TextMatrix(3, 4) = 9
End Sub

' ˵ءóӤѭ ... ͤŧ MS FlexGrid
Private Sub fgData_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
      
    ' кǹǤԴẺ ... 鹷ǧ ... 55555+ ... ҡҼ꡷ Header  ?????
    ' Ǩͺ˹觢ͧ᡹ y еͧդҹ¡Ҥ٧ͧá (Header)
    ' 蹡 ... ͡ Header ѧФѺ ... ͧ ... 繨ҡ
    ' Debug.Print "٧á = " & fgData.RowHeight(0) & vbCrLf & "ԡѴ y = " & y
    If y < fgData.RowHeight(0) Then
        
        ' кѡ㹡èѴ§
        fgData.Col = fgData.MouseCol
    
        ' 㹡èѴ§
        Call SortGrid
        
    End If

End Sub

Private Sub SortGrid()
    ' ѡɳТͧ Toggle  ÷ӧҹѺ
    ' 1 = èѴ§ҡҡ (Ascending - ASC)
    ' 2 = èѴ§ҡҡҹ (Descending - DESC)

    ' ҡ¨Ѵ§ҡҡҹ (SortOrder = 2) ...
    ' ͧŴŧ 1 Ѻ§ҡҡ  SortOrder = 1
    If SortOrder = 2 Then
        SortOrder = SortOrder - 1
    ' ҡ 2 ʴҤ SortOrder  0  1 ... 
    ' ҡ 0 ǡա 1  1 繡§Ẻҡ
    ' ҡ 1 ǡա 1  2 繡§Ẻҡҹ
    Else
        SortOrder = SortOrder + 1
    End If
    
    ' Ѵ§ҵѡ˹
    fgData.Sort = SortOrder
    
    ' ʴᶺʧáش
    SendKeys "{DOWN}"
    fgData.Col = 0
    fgData.Row = 0
    fgData.RowSel = 0
End Sub
Conclusion:
¹ҧҹ ෤ Ŵ ... سͧ繤ҡ ҡ ҡ֡ (㨨ТҴ͹) ͹ ... ѧҡ鹵ͧҧԹҡ 觷Դ ѹͧҧҡ Ѻͧ ǹѹһ͡繪鹧ҹ öٺ еͧ ...

͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560