如何设定MSHFlexgrid中包含 0 的单元格的背景颜色
如何设定MSHFlexgrid中包含 0 的单元格的背景颜色也就是说 MSHFlexgrid中凡是含有 0 的 背景颜色都改变。
需要代码。
谢谢。
程序代码:
Private Sub Form_Load()
Dim i As Integer, j As Integer
With MSFlexGrid1
.Rows = 10
.Cols = 10
For i = 0 To 9
For j = 0 To 9
.Row = j: .Col = i
If i = 0 Then
.CellBackColor = RGB(128, 128, 128)
Else
If j = 0 Then
.CellBackColor = RGB(128, 128, 128)
Else
.TextMatrix(i, j) = 1
.CellBackColor = RGB(0, 0, 0)
End If
End If
Next j
Next i
End With
End Sub

程序代码:
For i=0 to XXX
For j=0 to YYY
If Array(i, j) = 0 then
.CellBackColor = RGB(0, 0, 0)
.TextMatrix(i+1, j+1) = 0
Else
.CellBackColor = RGB(255, 255, 255)
.TextMatrix(i+1, j+1) = Array(i, j)
End if
Next j
Next i
程序代码:
For i=1 to XXX
For j=1 to YYY
If .TextMatrix(i, j) = 0 then
.CellBackColor = RGB(0, 0, 0)
.TextMatrix(i, j) = 0
Else
.CellBackColor = RGB(255, 255, 255)
End if
Next j
Next i

程序代码:
Option Explicit
Private Sub cmdCommand1_Click()
Dim i As Integer, j As Integer
With MSFlexGrid1
For i = 0 To 9
For j = 0 To 9
.TextMatrix(j + 1, i + 1) = j
If .TextMatrix(j + 1, i + 1) = 0 Then
.Row = j + 1: .Col = i + 1
.CellBackColor = RGB(255, 0, 0) '有不一样吗?
End If
Next j
Next i
End With
End Sub
Private Sub Form_Load()
Dim i As Integer, j As Integer
With MSFlexGrid1
.Rows = 11
.Cols = 11
End With
End Sub

程序代码:Private Sub Command1_Click()
For i = 0 To List1.ListCount - 2
a = Left(Right(List1.List(i), 3), 1)
c = Right(Right(List1.List(i), 3), 1)
d = Right(Val(a) + Val(c), 1)
MSFlexGrid1.TextMatrix(i + 2, 2) = d & " "
MSFlexGrid1.TextMatrix(i + 2, 3) = Right(a + 2, 1) & " "
If Right(a + 2, 1) = d Then
MSFlexGrid1.TextMatrix(i + 2, 4) = ""
Else
MSFlexGrid1.TextMatrix(i + 2, 4) = " √"
End If
Next
End Sub
Private Sub Form_Load()
MSFlexGrid1.Rows = 22
MSFlexGrid1.Cols = 5
For i = 2011001 To 2011020
List1.AddItem i
Next
End Sub
程序代码:Option Explicit
Private Const Square = " √" '这个改不改没差〜只是个人习惯而已〜
Private Sub Command1_Click()
Dim i As Long
Dim a As String, c As String, d As String
With MSFlexGrid1
For i = 0 To List1.ListCount - 2
a = Left(Right(List1.List(i), 3), 1)
c = Right(Right(List1.List(i), 3), 1)
d = Right(Val(a) + Val(c), 1)
.TextMatrix(i + 2, 2) = d & " "
.TextMatrix(i + 2, 3) = Right(a + 2, 1) & " "
If Right(a + 2, 1) = d Then
.TextMatrix(i + 2, 4) = ""
Else
.TextMatrix(i + 2, 4) = Square
.Row = i + 2: .Col = 4 '但是这行更重要〜一般人都会忽略这个〜MSFlexGrid的很笨〜不像EXCEL中会自己调整光标〜所以你要手动帮他指定位置〜
.CellBackColor = RGB(255, 0, 0) '还是这行没变〜
End If
Next i
End With
End Sub
Private Sub Form_Load()
Dim i As Long
MSFlexGrid1.Rows = 22
MSFlexGrid1.Cols = 5
For i = 2011001 To 2011020
List1.AddItem i
Next i
End Sub
[local]1[/local]
