为什么数据表表达式列只有在vb.net中才变为ready

问题描述 投票:0回答:1

我正在尝试,所以我想使用数据表表达式列来打印标签,所以下面我做了一个简单的示例,使用复选框从 datagridview1 移动到 datagridview2

我有下面的代码,但这仍然是错误的。

请指导我

谢谢

Public Class Form1
    Public dt As DataTable
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 dt = New DataTable
        dt.Columns.Add("A", GetType(String))
        dt.Columns.Add("B", GetType(String))
dt.Columns.Add("C", GetType(String), "TRIM(IIF(A Is Null Or SUBSTRING(A, 1, 1) = '-', '', A) + IIF(B Is Null Or SUBSTRING(B, 1, 1) = '-', '', ' ' + B))")
        dt.Rows.Add("BALOTELLY", "OLD WARDAH (02)")
        dt.Rows.Add("TOYOBO FODU THOMPSON", "LIGHT BLACK (12)")
        dt.Rows.Add("MCR", "-")
        dt.Rows.Add("WALLY COTTON CREAP", "-")
        dt.Rows.Add("WALLY COTTON CREAP", "BLACK (23)")
        dt.Rows.Add("-", "-")
        DataGridView1.DataSource = dt
        Dim CheckedBoxColumn As New DataGridViewCheckBoxColumn
        CheckedBoxColumn.Width = 40
        CheckedBoxColumn.Name = "checkboxcolumn"
        CheckedBoxColumn.HeaderText = "Check"
        DataGridView1.Columns.Insert(0, CheckedBoxColumn)
End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim count As Integer = 0
        For Each row2 As DataGridViewRow In DataGridView1.Rows
            Dim isselect As Boolean = Convert.ToBoolean(row2.Cells("checkboxcolumn").Value)
            If isselect Then
                count += 1
            End If
        Next row2
        Dim selectedRows As DataTable = dt.Clone
        For Each row2 As DataGridViewRow In DataGridView1.Rows
            Dim isselect As Boolean = Convert.ToBoolean(row2.Cells("checkboxcolumn").Value)
            If isselect Then
                Dim newRow As DataRow = selectedRows.Rows.Add()
                newRow("A") = dt.Rows(row2.Index)("A")
                newRow("B") = dt.Rows(row2.Index)("B")
'error below line code "Column "C" is ready only
                newRow("C") = dt.Rows(row2.Index)("C")
            End If
        Next row2
        DataGridView2.DataSource = selectedRows
        'theLabel.DataSource = selectedRows
    End Sub
End Class

vb.net datatable datagridview expression datacolumn
1个回答
0
投票

根据@dr.null的完美答案

谢谢你的帮助

      Dim selectedRows As DataTable = dt.Clone
selectedRows.Columns("C").Expression = Nothing : selectedRows.Columns("C").ReadOnly = False

© www.soinside.com 2019 - 2024. All rights reserved.