DataRepeater.DrawItem 事件
更新:2007 年 11 月
在必须绘制 DataRepeaterItem 时发生。
命名空间: Microsoft.VisualBasic.PowerPacks
程序集: Microsoft.VisualBasic.PowerPacks.Vs(在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
语法
声明
Public Event DrawItem As DataRepeaterItemEventHandler
用法
Dim instance As DataRepeater
Dim handler As DataRepeaterItemEventHandler
AddHandler instance.DrawItem, handler
public event DataRepeaterItemEventHandler DrawItem
public:
event DataRepeaterItemEventHandler^ DrawItem {
void add (DataRepeaterItemEventHandler^ value);
void remove (DataRepeaterItemEventHandler^ value);
}
JScript 不支持事件。
备注
使用此事件可更改 DataRepeaterItem 对象滚动到视图中时的外观。
在运行时,可基于条件设置每个项滚动到视图中时与外观相关的属性。 例如,在日程安排应用程序中,您可以更改某个项的背景颜色来警告用户该项已过期。 如果在类似 If¡Then 等条件语句中设置属性,则还必须使用 Else 子句指定不满足条件时的外观。
有关如何处理事件的更多信息,请参见使用事件。
示例
DataRepeater 控件的一些常见自定义项包括以交替颜色显示行以及基于条件更改字段的颜色。 下面的示例演示如何执行这些自定义项。 此示例假定您有一个 DataRepeater 控件,该控件已绑定到 Northwind 数据库中的 Products 表。
Private Sub DataRepeater1_DrawItem(ByVal sender As Object, ByVal e _
As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) _
Handles DataRepeater1.DrawItem
' Alternate the back color.
If (e.DataRepeaterItem.ItemIndex Mod 2) <> 0 Then
' Apply the secondary back color.
e.DataRepeaterItem.BackColor = Color.AliceBlue
Else
' Apply the default back color.
DataRepeater1.ItemTemplate.BackColor = Color.White
End If
' Change the color of out-of-stock items to red.
If e.DataRepeaterItem.Controls(UnitsInStockTextBox.Name).Text _
< 1 Then
e.DataRepeaterItem.Controls(UnitsInStockTextBox.Name). _
BackColor = Color.Red
Else
e.DataRepeaterItem.Controls(UnitsInStockTextBox.Name). _
BackColor = Color.White
End If
End Sub
private void dataRepeater1_DrawItem(object sender,
Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs e)
{
// Alternate the back color.
if ((e.DataRepeaterItem.ItemIndex % 2) != 0)
// Apply the secondary back color.
{
e.DataRepeaterItem.BackColor = Color.AliceBlue;
}
else
{
// Apply the default back color.
dataRepeater1.ItemTemplate.BackColor = Color.White;
}
// Change the color of out-of-stock items to red.
if (e.DataRepeaterItem.Controls["unitsInStockTextBox"].Text == "0")
{
e.DataRepeaterItem.Controls["unitsInStockTextBox"].BackColor = Color.Red;
}
else
{
e.DataRepeaterItem.Controls["unitsInStockTextBox"].BackColor = Color.White;
}
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
Microsoft.VisualBasic.PowerPacks 命名空间