vb.net datagrid to datagridview winforms



我们与 vb.net 合作 - Visual Studio 2013 (WinForms(我们正在代码中将数据网格更改为数据网格视图。目前,我正在尝试转换数据网格中描述的列,如下所示:

Dim grdcolstyle5 As New PTSoft.FrameWork.DataBrowserTextColumnColorDecimal
With grdcolstyle5
.HeaderText = "text"
.MappingName = "vrd_199"
.Width = 80
.FormatString = "###,###,##0.00"
.[Operator] = "<"
.ParameterCol = 2
.ForeBrush = New SolidBrush(Color.Red)
End With

它的作用是将一列的值与另一列的值进行比较,并在文本较小时为文本着色(在本例中(。我知道如何在网格填满后循环执行此操作,但这会减慢速度。有谁知道如何在行被填满的那一刻"即时"完成此操作?

简而言之,我正在寻找数据网格视图的等效物...

您可以使用

RowPrePaint事件,其中有大量行要绘制。

Private Sub dataGridView1_RowPrePaint(ByVal sender As Object, ByVal e As DataGridViewRowPrePaintEventArgs)
If Convert.ToInt32(dataGridView1.Rows(e.RowIndex).Cells(2).Text) < Convert.ToInt32(dataGridView1.Rows(e.RowIndex).Cells(5).Text) Then
    dataGridView1.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Red
End If
End Sub

上面的代码正在比较单元格(2(和单元格(5(。您可以根据需要对其进行自定义。

另一种选择是使用CellFormattingEvent

Private Sub dataGridView1_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs)
    For Each Myrow As DataGridViewRow In dataGridView1.Rows
        If Convert.ToInt32(Myrow.Cells(2).Value) < Convert.ToInt32(Myrow.Cells(1).Value) Then
            Myrow.DefaultCellStyle.ForeColor = Color.Red
        End If
    Next
End Sub

最新更新