Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 函数中的泛型_Vb.net_Datagridview - Fatal编程技术网

Vb.net 函数中的泛型

Vb.net 函数中的泛型,vb.net,datagridview,Vb.net,Datagridview,我想格式化datagridview中有关对象“status”属性的行。FormatRow函数可以接收任何类型的对象。我想出了这个函数: Private Sub FormatRow(Of T)() For Each row As DataGridViewRow In dgvHistory.Rows Dim obj As T = CType(row.DataBoundItem, T) If obj.**Status** = BLL.Configurati

我想格式化datagridview中有关对象“status”属性的行。FormatRow函数可以接收任何类型的对象。我想出了这个函数:

Private Sub FormatRow(Of T)()

    For Each row As DataGridViewRow In dgvHistory.Rows

        Dim obj As T = CType(row.DataBoundItem, T)

        If obj.**Status** = BLL.Configuration.HISTORY_STATUS_ACTIVE Then
            row.DefaultCellStyle.ForeColor = Color.Green
            row.DefaultCellStyle.Font = New Font(Control.DefaultFont, FontStyle.Bold)
        End If

    Next

End Sub
但我不能走正确的路。在IF语句中,“status”属性不可用,因为我的行对象的类型转换不正确

有什么想法吗?谢谢。

我将用C#回答,你来做转换

创建一个接口IStatus或类似的包含Status属性的接口。 让您的实体实现此接口

如下定义您的函数:

private void FormatRow<T>() where T: IStatus
private void FormatRow(),其中T:IStatus
这应该能奏效