DataRepeaterItemEventArgs 类

更新:2007 年 11 月

提供 DrawItem 事件的数据。

命名空间:  Microsoft.VisualBasic.PowerPacks
程序集:  Microsoft.VisualBasic.PowerPacks.Vs(在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

语法

声明
Public Class DataRepeaterItemEventArgs _
    Inherits EventArgs
用法
Dim instance As DataRepeaterItemEventArgs
public class DataRepeaterItemEventArgs : EventArgs
public ref class DataRepeaterItemEventArgs : public EventArgs
public class DataRepeaterItemEventArgs extends EventArgs

备注

使用 DrawItem 事件可更改 DataRepeaterItem 对象滚动到视图中时的外观。

在运行时,可基于条件设置与外观相关的属性。 例如,在日程安排应用程序中,您可以更改某个项的背景颜色来警告用户该项已过期。 如果在类似 If...Then 等条件语句中设置属性,则还必须使用 Else 子句指定不满足条件时的外观。

示例

下面的示例演示如何使用 DrawItem 事件处理程序在项滚动到视图中时进行更改。 此示例假定您有一个 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;
    }
}

继承层次结构

System.Object
  System.EventArgs
    Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

另请参见

参考

DataRepeaterItemEventArgs 成员

Microsoft.VisualBasic.PowerPacks 命名空间

DrawItem

其他资源

DataRepeater 控件简介 (Visual Studio)

如何:更改 DataRepeater 控件的外观 (Visual Studio)