Copy một dòng từ DataGridView sang DataTable


VB:

Sử dụng: DataGridView.Clone(), DataTable.NewRow(), DataTable.Rows.Add()

Dim dt As New DataTable()
Dim dtrow As DataRow
'Sao chep ten cot vao DataTable dt sử dụng Clone()
dt = CType(Me.DataGridView_M.DataSource, DataTable).Clone
For i = 0 To DataGridView_M.Rows.Count - 1
    If DataGridView_M.Rows(i).Cells("QUANTITY").Value <> Nothing Then
        If Convert.ToDouble(DataGridView_M.Rows(i).Cells("QUANTITY").Value.ToString()) > 0.0 Then
            dtrow = dt.NewRow()
            For j = 0 To dt.Columns.Count - 1
                dtrow(j) = DataGridView_M.Rows(i).Cells(j).Value
            Next
            dt.Rows.Add(dtrow)
        End If
    End If
Next

Copy »


Keywords: Copy 1 Row từ DataGridView sang DataTable

TOP