以下是引用yangming在2009-6-10 13:00:00的发言:
DrawCell
在绘制单元格的时候执行。
e参数属性有:
Form: 触发事件的窗口
Sender: 触发事件的控件
DataRow: 正在绘制的数据行
ColName: 正在绘制的列的名称
Style: 用于绘制单元格的样式名称
示例
假定DataList用于显示订单数据,我们希望对于大于5000的金额,用红底蓝字标出,对于大于4000的金额,用蓝底白字标出。
首先在窗口的AfterLoad事件中设置代码,增加两个样式:
Dim
dst As WinForm.DataList = e.Form.Controls("DataList1")
dst.AddUserStyle("a",Color.Red,Color.Blue)
dst.AddUserStyle("b",Color.Blue,Color.White)
然后将DataList的DrawCell事件设为:
If
e.ColName = "金额" Then
Dim Val As Double = e.DataRow("金额")
if Val > 5000 Then
e.Style = "a"
ElseIf Val > 4000 Then
e.Style= "b"
End If
End If
如是DataList,也可以看帮助中的"DataList的颜色标记功能"
[此贴子已经被作者于2009-6-10 13:01:00编辑过]
我在datalist试出来了,但是试了以后我只能做到整张表的所要的数据用颜色显示,我想要效果是在筛选后标出.不是整个表都显示.我做不出来.比如我用这个代码筛选数据:
with e.Form
if e.sender.text <> "请输入关键字" then
Dim dst As WinForm.DataList = .Controls("DataList1")
Dim txb1 As WinForm.TextBox = .Controls("TextBox1")
dst.RowFilter = "[联系人] Like '*" & txb1.text & "*' or [客户编号] Like '*" & txb1.text & "*'or [客户名称] Like '*" & txb1.text & "*'or [地址] Like '*" & txb1.text & "*'"
end with
举了例子,我筛选客户编号为"52033",筛选后"52033"用颜色表示出来.这个代码怎么写?