创建网格视图自定义单元格
本文关键字:单元格 自定义 视图 网格 创建 | 更新日期: 2023-09-27 18:35:23
我有Winforms
应用程序和Telerik GridView
.
我想要实现的只是自定义创建自定义单元格并将PregressBar
添加到Cell GridView
中,所以我找到了本教程来解释如何做到这一点,但由于我是非常新的开发人员,所以我很难理解如何使用它来实现这一点。
我所做的只是创建这两个类:ProgressBarCellElement
和 ProgressBarColumn
所以我问你是否可以帮我。我知道问这种问题并不常见,但我尽了一切努力,但仍然不知道如何使用它。
更新:
这个操作系统我尝试过(不起作用):
private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
if (e.CellType == typeof(GridDataCellElement))
{
GridViewDataColumn dataColumn = e.Column as GridViewDataColumn;
if (dataColumn.UniqueName == "Progress")
{
e.CellType = typeof(ProgressBarColumn);
}
}
}
下面是一个例子。这是主要形式。
Public Partial Class Form1
Inherits Form
Private radGridView1 As RadGridView
Public Sub New()
InitializeComponent()
radGridView1 = New RadGridView()
Me.Controls.Add(radGridView1)
radGridView1.Dock = DockStyle.Fill
Dim textCol As New GridViewTextBoxColumn("Name")
radGridView1.Columns.Add(textCol)
Dim ageCol As New GridViewDecimalColumn("Age")
radGridView1.Columns.Add(ageCol)
Dim prgsCol As New ProgressBarColumn("Progress")
radGridView1.Columns.Add(prgsCol)
radGridView1.Rows.Add("Steve", 21, 15)
radGridView1.Rows.Add("John", 43, 90)
radGridView1.Rows.Add("Mike", 23, 66)
End Sub
End Class
这是进度条单元格。
Class ProgressBarCellElement
Inherits GridDataCellElement
Private radProgressBarElement As RadProgressBarElement
Public Sub New(column As GridViewColumn, row As GridRowElement)
MyBase.New(column, row)
End Sub
Protected Overrides Sub CreateChildElements()
MyBase.CreateChildElements()
radProgressBarElement = New RadProgressBarElement()
Me.Children.Add(radProgressBarElement)
End Sub
Protected Overrides Sub SetContentCore(value As Object)
If Me.Value IsNot Nothing AndAlso Me.Value <> DBNull.Value Then
Me.radProgressBarElement.Value1 = Convert.ToInt32(Me.Value)
End If
End Sub
Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
Get
Return GetType(GridDataCellElement)
End Get
End Property
Public Overrides Function IsCompatible(data As GridViewColumn, context As Object) As Boolean
Return TypeOf data Is ProgressBarColumn AndAlso TypeOf context Is GridDataRowElement
End Function
End Class
这是进度条列。
Public Class ProgressBarColumn
Inherits GridViewDataColumn
Public Sub New(fieldName As String)
MyBase.New(fieldName)
End Sub
Public Overrides Function GetCellType(row As GridViewRowInfo) As Type
If TypeOf row Is GridViewDataRowInfo Then
Return GetType(ProgressBarCellElement)
End If
Return MyBase.GetCellType(row)
End Function
End Class