更新: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
執行緒安全
這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間