使用MsFlexGrid控制元件的幾個函式 (轉)

gugu99發表於2008-07-11
使用MsFlexGrid控制元件的幾個函式 (轉)[@more@]

在VB處理資料顯示的時候,使用表格是一種好的方法,雖然DataGrid可以與資料來源繫結,但是總有美中不足,就是外觀不好看,所以有時應用MlexGrid顯示資料還是一種比較好的方法,以下幾個是用來控制MsFlexGrid的

(本人語言表達能力有限,還請見諒)

 

'MsFlexGrid操作函式

'合併列
Public Function MergeCol(GridObj As , ByVal StartCol As Long, ByVal EndCol As Long, ByVal ColValue As String, ByVal CurrentRow As Long) As Boolean
If StartCol > EndCol Or StartCol > GridObj.Cols Or CurrentRow > GridObj.Rows Then
    MsgBox "對不起,行列設定錯誤!", vbOKOnly, App.Title
    MergeCol = False
    Exit Function
End If

For I = StartCol To EndCol
GridObj.MergeCol(I) = True
GridObj.TextArray(faIndex(GridObj, CurrentRow, I)) = ColValue
GridObj.ColAlignment(I) = flexAlignCenterCenter
Next I


GridObj.MergeRow(CurrentRow) = True

MergeCol = True

End Function




'合併行
Public Function MergeRow(GridObj As Object, ByVal StartRow As Long, ByVal EndRow As Long, ByVal RowValue As String, ByVal CurrentCol As Long) As Boolean
If StartRow > EndRow Or StartRow > GridObj.Rows Or CurrentCol > GridObj.Cols Then
    MsgBox "對不起,行列設定錯誤!", vbOKOnly, App.Title
    MergeRow = False
    Exit Function
End If

For I = StartRow To EndRow
GridObj.MergeRow(I) = True
GridObj.TextArray(faIndex(GridObj, I, CurrentCol)) = RowValue
GridObj.ColAlignment(CurrentCol) = flexAlignCenterCenter

Next I
GridObj.MergeCol(CurrentCol) = True
MergeRow = True

End Function

'轉換
Public Function faIndex(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As Long
If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
    MsgBox "對不起,行列設定錯誤!", vbOKOnly, App.Title
    faIndex = -1
   
    Exit Function
End If

faIndex = row * GridObj.Cols + col

End Function


'插入行
Public Function SetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer, ByVal SetValue As String) As Boolean
If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
    MsgBox "對不起,行列設定錯誤!", vbOKOnly, App.Title
    SetItem = False
    Exit Function
End If
    GridObj.TextArray(faIndex(GridObj, row, col)) = SetValue
   
    SetItem = True
End Function

'得到單元格值
Public Function GetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As String

If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
    MsgBox "對不起,行列設定錯誤!", vbOKOnly, App.Title
    GetItem = ""
    Exit Function
End If
    GetItem = GridObj.TextArray(faIndex(GridObj, row, col))
End Function



這是我以前寫的幾個函式,不知能不能幫上你, 我弄時間挺長,有什麼問題可以給我發E_


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-1007109/,如需轉載,請註明出處,否則將追究法律責任。

相關文章