扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:Microsoft 2007年11月8日
关键字: Windows
DataGridColumn 属性 FooterStyle (TableItemStyle) FooterText(字符串) HeaderImageUrl(字符串) HeaderStyle (TableItemStyle) HeaderText(字符串) ItemStyle (TableItemStyle) SortExpression(字符串) Visible(布尔值) DataGridColumn 方法 Initialize InitializeCell LoadViewState OnColumnChanged SaveViewState TrackViewState |
Namespace MyCustomColumn Public Class DropDownColumn Inherits DataGridColumn Public DataSource As ICollection Public DataField As String Public DataTextField As String Public DataValueField As String End Class End Namespace |
Public Overrides Sub InitializeCell(ByVal cell As TableCell, _ ByVal columnIndex As Integer, _ ByVal itemType As ListItemType) MyBase.InitializeCell(cell, columnIndex, itemType) Select Case itemType Case ListItemType.Header cell.Text = HeaderText Case ListItemType.Item, ListItemType.AlternatingItem AddHandler cell.DataBinding, AddressOf ItemDataBinding Case ListItemType.EditItem AddHandler cell.DataBinding, AddressOf EditItemDataBinding Dim DDL As New DropDownList cell.Controls.Add(DDL) End Select End Sub |
Private Sub ItemDataBinding(ByVal sender As Object, ByVal e As EventArgs) Dim cell As TableCell = CType(sender, TableCell) Dim DGI As DataGridItem = CType(cell.NamingContainer, DataGridItem) Try cell.Text = DGI.DataItem(DataField) Catch RangeEx As IndexOutOfRangeException Throw New Exception("Specified DataField was not found.") Catch OtherEx As Exception Throw New Exception(OtherEx.InnerException.ToString) End Try End Sub |
Private Sub EditItemDataBinding(ByVal sender As Object, _ ByVal e As EventArgs) Dim cell As TableCell = CType(sender, TableCell) Dim DDL As DropDownList = _ CType(cell.Controls(0), DropDownList) Dim DataSourceItem As Object Dim item As ListItem Dim DGI As DataGridItem '首先添加一个空选项 DDL.Items.Add(New ListItem("")) For Each DataSourceItem In DataSource Select Case DataSourceItem.GetType.ToString Case "System.String" '应用到 ArrayList 示例 item = New ListItem(DataSourceItem, DataSourceItem) DDL.Items.Add(item) Case "System.Data.DataRowView" Dim DRV As DataRowView = _ CType(DataSourceItem, DataRowView) item = New_ ListItem(DRV(DataTextField), DRV(DataValueField)) DDL.Items.Add(item) Case Else Throw New Exception("Invalid DataSource type.") End Select Next Try DGI = CType(cell.NamingContainer, DataGridItem) item = DDL.Items.FindByValue(DGI.DataItem(DataField)) Catch RangeEx As IndexOutOfRangeException Throw New Exception("Specified DataField was not found.") Catch OtherEx As Exception Throw New Exception(OtherEx.InnerException.ToString) End Try If Not item Is Nothing Then item.Selected = True End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者