vbmsflexgridʹþ
MSFlexGridؼʾͲݡ԰ַͼƬıṩ򡢲ݺ͸ʽŹܡDataؼʱMSFlexGridؼֻʾֻݡ
    MSFlexGridеκεԪıͼƬߡRowColָMSFlexGridؼĵǰԪڴָǰԪҲʱʹ̸ı䵱ǰԪText˵ǰԪеı

1 ıֵMsFlexGridĵԪ 
MsFlexGrid.TextMatrix(3,1)=Hello 

2 MsFlexGridؼԪв뱳ͼ 
Set MsFlexGrid.CellPicture=LoadPicture(C:\temp\1.bmp) 

3ѡĳԪ 
MsFlexGrid.Row=1 
MsFlexGrid.Col=1 

4ôʽǰѡеԪ 
MsFlexGrid.CellFontBold=True 

5 µһ 
ʹAddItem,TabַֿͬԪ 
dim row as string 
row=AAA&vbtab&bbb 
MsFlexGrid1.addItem row 


6ʵMSFlexGridؼбΪɫ˫бΪɫ? 
    Dim i As Integer 
    With MSFlexGrid1 
         .AllowBigSelection = True     ʽ 
         .FillStyle = flexFillRepeat 
         For i = 0 To .Rows - 1 
             .Row = i: .Col = .FixedCols 
             .ColSel = .Cols() - .FixedCols - 1 
             If i Mod 2 = 0 Then 
                .CellBackColor = &HC0C0C0     ǳ 
             Else 
                .CellBackColor = vbBlue  ɫ 
             End If 
         Next i 
     End With 

7MSFlexGridؼƵһ 
MSFlexGrid1.TopRow = MSFlexGrid1.Rows C 1 

8жmsflexgrid޹ 
Declare Function GetScrollRange Lib "user32" (ByVal hWnd As Long, ByVal nBar As Long, lpMinPos As Long, lpMaxPos As Long) As Long 
Public Const SB_HORZ = &H0 
Public Const SB_VERT = &H1 

Public Function VsScroll(MshGrid As MSHFlexGrid) As Boolean           жˮƽĿɼ 
Dim i As Long 
VsScroll = False 
i = GetScrollRange(MshGrid.hWnd, SB_HORZ, lpMinPos, lpMaxPos) 
If lpMaxPos <> lpMinPos Then VsScroll = True 
End Function 

Public Function HeScroll(MshGrid As MSHFlexGrid) As Boolean           жϴֱĿɼ 
Dim i As Long 
HeScroll = False 
i = GetScrollRange(MshGrid.hWnd, SB_VERT, lpMinPos, lpMaxPos) 
If lpMaxPos <> lpMinPos Then HeScroll = True 
End Function 

9ʱ붯̬MSFlexgrid 
ڵ2кһУ 
Private Sub Form_Load() 
Me.MSHFlexGrid1.Cols = 5 
MSHFlexGrid1.Rows = 2 
For i = 0 To Me.MSHFlexGrid1.Cols - 1 
Me.MSHFlexGrid1.TextMatrix(0, i) = i 
Me.MSHFlexGrid1.TextMatrix(1, i) = i 
Next 
End Sub 

Private Sub Command1_Click() 
Me.MSHFlexGrid1.Cols = Me.MSHFlexGrid1.Cols + 1 
Me.MSHFlexGrid1.ColPosition(5) = 3 
End Sub 

10 MSFlexGridеĶ빦ܵʹ 
MSFlexGrid1.ColAlignment(index)=n 


11õMSFlexGridؼеǰѡеһ 
msflexgrid1.rowselǵǰѡ 

12 ͨп 
msflexgrid1.colwidth(i)=4000
 MsFlexGrid ı༭ [ת]

MsFlexGrid ؼûṩı༭ĹܣʾһTextBox ʵֱ༭ǰĹܡ

ڰһ ͰTextBox ƶǰλã  ڼسƶʱ ͰTextBox еݷŵС 

ʵֲ
1  VB5 һµĹ̡

2 ڲ˵̡ ѡ  бѡ Microsoft FlexGrid Control ..

3 һ MsFlexGrid ؼһTextBox ؼ(Text1) Form1 ޸MsFlexGrid ؼΪ Grid1 Grid1 У Ϊ 4 ̶УΪ 0  Text1  Visiable Ϊ False BorderStyle Ϊ None(0)

4 Form1 Ĵ

Const ASC_ENTER = 13 'س
Dim gRow As Integer
Dim gCol As Integer

5 Ӵ뵽 Grid_KeyPress ̣

Private Sub Grid1_KeyPress(KeyAscii As Integer)
' Move the text box to the current grid cell:
Text1.Top = Grid1.CellTop + Grid1.Top
Text1.Left = Grid1.CellLeft + Grid1.Left
' Save the position of the grids Row and Col for later:
gRow = Grid1.Row
gCol = Grid1.Col
' Make text box same size as current grid cell:
Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX
Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY
' Transfer the grid cell text:
Text1.Text = Grid1.Text
' Show the text box:
Text1.Visible = True
Text1.ZOrder 0 '  Text1 ŵǰ棡
Text1.SetFocus
' Redirect this KeyPress event to the text box:
If KeyAscii <> ASC_ENTER Then
SendKeys Chr$(KeyAscii)
End If
End Sub

6 Ӵ뵽 Text1_KeyPress ̣

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = ASC_ENTER Then
Grid1.SetFocus ' Set focus back to grid, see Text_LostFocus.
KeyAscii = 0 ' Ignore this KeyPress.
End If
End Sub

7 Ӵ뵽 Text1_LostFocus ̣

Private Sub Text1_LostFocus()
Dim tmpRow As Integer
Dim tmpCol As Integer
' Save current settings of Grid Row and col. This is needed only if
' the focus is set somewhere else in the Grid.
tmpRow = Grid1.Row
tmpCol = Grid1.Col
' Set Row and Col back to what they were before Text1_LostFocus:
Grid1.Row = gRow
Grid1.Col = gCol
Grid1.Text = Text1.Text ' Transfer text back to grid.
Text1.SelStart = 0 ' Return caret to beginning.
Text1.Visible = False ' Disable text box.
' Return row and Col contents:
Grid1.Row = tmpRow
Grid1.Col = tmpCol
End Sub

 
