我建议你用MSFlexGrid1 VB中MsFlexGrid控件的使用细则(收集) >> 将文本赋值给MsFlexGrid的单元格 MsFlexGrid.TextMatrix(3,1)=”Hello” >> 在MsFlexGrid控件单元格中插入背景图形 Set MsFlexGrid.CellPicture=LoadPicture(“C:\temp\1.bmp”) >>选中某个单元 MsFlexGrid.Row=1 MsFlexGrid.Col=1 >>用粗体格式化当前选中单元 MsFlexGrid.CellFontBold=True >> 添加新的一行 使用AddItem方法,用Tab字符分开不同单元格的内容 dim row as string row=”AAA”&vbtab&”bbb” MsFlexFrid1.addItem row >>怎样来实现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 >> MSFlexGrid控件如何移到最后一行 MSFlexGrid1.TopRow = MSFlexGrid1.Rows – 1 >>如何判断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 >>程序运行时,想动态增加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 >> 请教MSFlexGrid中的对齐功能的使用 设置MSFlexGrid1.ColAlignment(index)=n >>得到MSFlexGrid控件中当前选中的一行 msflexgrid1.rowsel就是当前选中行 >> 如何通过代码调节列宽度 msflexgrid1.colwidth(i)=4000
Private Sub DataGrid1_RowColChange(lastrow As String, lastcol As Integer) '此时,你所点击的单元格成为当前单元格 Msgbox ADODC1.Text End Sub
datagrid1.row=0 datagrid1.col=1 aa=datagrid1.text
已经解决:方法如下,请高手点评! Private Sub DataGrid1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Dim Serkey As String j = DataGrid1(0).RowContaining(Y) If (j <> -1) Then DataGrid1(0).Row = DataGrid1(0).RowContaining(Y) '取得行值 SerKey = DataGrid1(0).Columns(7).Text '取指定列值,即我想要的内容 txtSerK = SerKey '显示取值,用于测试 End If End Sub
简单,只要这样就行了: Private Sub DataGrid1_RowColChange(lastrow As String, lastcol As Integer) Msgbox DataGrid1.Text End Sub
Private Sub DataGrid1_RowColChange(lastrow As String, lastcol As Integer) Msgbox DataGrid1.Text End Sub
VB中MsFlexGrid控件的使用细则(收集) >> 将文本赋值给MsFlexGrid的单元格
MsFlexGrid.TextMatrix(3,1)=”Hello” >> 在MsFlexGrid控件单元格中插入背景图形
Set MsFlexGrid.CellPicture=LoadPicture(“C:\temp\1.bmp”) >>选中某个单元
MsFlexGrid.Row=1
MsFlexGrid.Col=1 >>用粗体格式化当前选中单元
MsFlexGrid.CellFontBold=True >> 添加新的一行
使用AddItem方法,用Tab字符分开不同单元格的内容
dim row as string
row=”AAA”&vbtab&”bbb”
MsFlexFrid1.addItem row
>>怎样来实现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 >> MSFlexGrid控件如何移到最后一行
MSFlexGrid1.TopRow = MSFlexGrid1.Rows – 1 >>如何判断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 >>程序运行时,想动态增加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 >> 请教MSFlexGrid中的对齐功能的使用
设置MSFlexGrid1.ColAlignment(index)=n
>>得到MSFlexGrid控件中当前选中的一行
msflexgrid1.rowsel就是当前选中行 >> 如何通过代码调节列宽度
msflexgrid1.colwidth(i)=4000
'此时,你所点击的单元格成为当前单元格
Msgbox ADODC1.Text
End Sub
datagrid1.row=0
datagrid1.col=1
aa=datagrid1.text
Private Sub DataGrid1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Serkey As String
j = DataGrid1(0).RowContaining(Y)
If (j <> -1) Then
DataGrid1(0).Row = DataGrid1(0).RowContaining(Y) '取得行值
SerKey = DataGrid1(0).Columns(7).Text '取指定列值,即我想要的内容
txtSerK = SerKey '显示取值,用于测试
End If
End Sub
Private Sub DataGrid1_RowColChange(lastrow As String, lastcol As Integer) Msgbox DataGrid1.Text
End Sub
Msgbox DataGrid1.Text
End Sub