我写的代码是:
Do While daReRs.EOF = False
If Format(daReRs.Fields("日期"), "yyyy-mm-dd") <= DateAdd("d", -2, Date) Then
RSellGrid.ForeColor = vbBlue
End If
If Format(daReRs.Fields("日期"), "yyyy-mm-dd") >= DateAdd("m", -3, Date) Then
RSellGrid.ForeColor = vbRed
End If
If Format(daReRs.Fields("日期"), "yyyy-mm-dd") <= DateAdd("d", -2, Date) And Format(daReRs.Fields("日期"), "yyyy-mm-dd") >= DateAdd("m", -3, Date) Then
RSellGrid.ForeColor = vbBlack
End If
daReRs.MoveNext
Loop但是实现不了.或者是有别的控件更好的用请推荐一下,谢谢!!
Do While daReRs.EOF = False
If Format(daReRs.Fields("日期"), "yyyy-mm-dd") <= DateAdd("d", -2, Date) Then
RSellGrid.ForeColor = vbBlue
End If
If Format(daReRs.Fields("日期"), "yyyy-mm-dd") >= DateAdd("m", -3, Date) Then
RSellGrid.ForeColor = vbRed
End If
If Format(daReRs.Fields("日期"), "yyyy-mm-dd") <= DateAdd("d", -2, Date) And Format(daReRs.Fields("日期"), "yyyy-mm-dd") >= DateAdd("m", -3, Date) Then
RSellGrid.ForeColor = vbBlack
End If
daReRs.MoveNext
Loop但是实现不了.或者是有别的控件更好的用请推荐一下,谢谢!!
Format(daReRs.Fields("日期"), "yyyy-mm-dd")
这一段不就可以把数据库中的日期转化为yyyy-mm-dd格式的了?
另外再说一下,数据库我是用access的
另外你的代码只是把数据库中所有的日期判断了一遍,并没有根据判断结果来设置相应单元格的颜色。
用这个不行的么??
RSellGrid.col=4
然后才能RSellGrid.ForeColor = vbBlue
否则你遍历完数据库中的所有日期,设置的也不过是同一个单元格的颜色而已。
实际上你应该这样做:在将日期写入RSellGrid中的时候,接着就对日期进行判断并设置颜色,比如将代码修改为:
dim lRow as long,dim lCol as long
lRow=0:lCol=0
Do While daReRs.EOF = False
RSellGrid.row=lRow
RSellGrid.col=lCol
RSellGrid.text=Format(daReRs.Fields("日期"), "yyyy-mm-dd")
If cDate(Format(daReRs.Fields("日期"), "yyyy-mm-dd")) <= DateAdd("d", -2, Date) Then
RSellGrid.ForeColor = vbBlue
End If
If cDate(Format(daReRs.Fields("日期"), "yyyy-mm-dd")) >= DateAdd("m", -3, Date) Then
RSellGrid.ForeColor = vbRed
End If
If cDate(Format(daReRs.Fields("日期"), "yyyy-mm-dd")) <= DateAdd("d", -2, Date) And cDate(Format(daReRs.Fields("日期"), "yyyy-mm-dd")) >= DateAdd("m", -3, Date) Then
RSellGrid.ForeColor = vbBlack
End If
daReRs.MoveNext
lRow=lRow+1
Loop
我是估计着改的,不大清楚MSHFlexGrid这个控件是不是有这些属性,也不知道row和col这两个属性的起始值是0还是1,你运行一下试试看吧,呵呵
dim lRow as long,lCol as long
RSellGrid.row =1 lRow = 2当表只有一项的时候到是成功了.
RSellGrid.rows=RSellGrid.rows+1
RSellGrid.row=lRow
RSellGrid.col=lCol
RSellGrid.text=Format(daReRs.Fields("日期"), "yyyy-mm-dd")
.......
问题应该是这个语句,着色是整张表的.还有其他的控件吗?你是用什么控件的啊??
lRow = 0: lCol = 0
Do While reNewRs.EOF = False
RSellGrid.Rows = RSellGrid.Rows + 1
RSellGrid.row = lRow
RSellGrid.Col = lCol
RSellGrid.Text = Format(reNewRs.Fields("日期"), "yyyy-mm-dd")
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) >= DateAdd("d", -2, Date) Then
RSellGrid.CellForeColor = vbBlue
End If
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) <= DateAdd("m", -3, Date) Then
RSellGrid.CellForeColor = vbRed
End If
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) < DateAdd("d", -2, Date) And CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) > DateAdd("m", -3, Date) Then
RSellGrid.CellForeColor = vbBlack
End If
reNewRs.MoveNext
lRow = lRow + 1
Loop
Set RSellGrid.DataSource = reNewRs
lbCount(1).Caption = reNewRs.RecordCount
Set reNewRs = Nothing
我的代码是这样写的啊,但是字体还是黑色.........
Dim i As Integer
MSHFlexGrid1.Rows = 100
For i = 1 To 97 Step 3
With MSHFlexGrid1
.TextMatrix(i, 1) = Format(Date - 2, "yyyy-mm-dd")
.Row = i
.CellForeColor = vbRed
.TextMatrix(i + 1, 1) = Format(Date, "yyyy-mm-dd")
.Row = i + 1
.CellForeColor = vbGreen
.TextMatrix(i + 2, 1) = Format(Date + 2, "yyyy-mm-dd")
.Row = i + 2
.CellForeColor = vbYellow
End With
Next
End Sub
对某一格用不同颜色时,row值应该改变
With RSellGrid
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) >= DateAdd("d", -2, Date) Then
.Rows = i
.CellForeColor = vbBlue
End If
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) <= DateAdd("m", -3, Date) Then
.Rows = i + 1
.CellForeColor = vbRed
End If
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) < DateAdd("d", -2, Date) And CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) > DateAdd("m", -3, Date) Then
.Rows = i + 2
.CellForeColor = vbBlack
End If
End With
Next我是这样写的,还是不行哦........
with RSellGrid
for i=1 to .rows-1
.row=i
……
…… If CDateFormat(reNewRs.Fields("日期"), "yyyy-mm-dd")) >= DateAdd("d", -2, Date) Then
.CellForeColor = vbBlue
End If
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) <= DateAdd("m", -3, Date) Then
.CellForeColor = vbRed
End If
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) < DateAdd("d", -2, Date) And CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) > DateAdd("m", -3, Date) Then
.CellForeColor = vbBlack
End If
next end with 要区分rows与row 的区别
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) >= DateAdd("d", -2, Date) Then
RSellGrid.row = i
For c = 0 To 18
RSellGrid.Col = c
RSellGrid.CellForeColor = RGB(0, 0, 255)
Next
End If
If CDate(Format(reNewRs.Fields("日期"), "yyyy-mm-dd")) <= DateAdd("m", -3, Date) Then
RSellGrid.row = i
For c = 0 To 18
RSellGrid.Col = c
RSellGrid.CellForeColor = RGB(255, 0, 0)
Next
End If
reNewRs.MoveNext
Next
For c = 0 To 18
RSellGrid.Col = c
RSellGrid.CellForeColor = RGB(255, 0, 0)
Next这一句有没有可以实现整行填色的啊?用循环好象很慢.....