<VB.NET> DataGridView To DataTable
2020. 5. 25. 14:33ㆍVB.NET
728x90
반응형
DataBinding 안되어있는 DataGridView를 DataTable로 변환 하는 코드
''' <summary> ''' DataGridView To DataTable ''' </summary> ''' <param name="dgv"> 변환 할 DataGridView를 넣는다.</param> ''' <returns></returns> Private Function DataGridViewToDataTable(ByRef dgv As DataGridView) As DataTable Dim _dt As DataTable = New DataTable
If _dt.Columns.Count = 0 Then For Each dgdr As DataGridViewColumn In dgv.Columns _dt.Columns.Add(dgdr.HeaderText) Next End If
For Each row As DataGridViewRow In dgv.Rows Dim dRow As DataRow = _dt.NewRow()
For j As Integer = 0 To row.Cells.Count - 1 dRow(j) = row.Cells(j).Value Next _dt.Rows.Add(dRow) Next
Return _dt
End Function |
728x90
반응형
'VB.NET' 카테고리의 다른 글
VB.NET 복사 붙여넣기 / insert into / update table set 등등 잡다 source Mysql/Access(accdb)/ExcelDB (0) | 2020.12.16 |
---|---|
VB.NET/C# DataTable 여러 컬럼 정렬하기, Multiple Column Sort (1) | 2020.06.02 |
<VB.NET> DataTable To DataGridView (0) | 2020.05.22 |
VB.NET TextBox에 숫자만입력받기(실수만 입력받기, 정수만 입력받기) (0) | 2020.04.10 |
VB.NET DataGridView 속도개선하기 (DoubleBuffered 이용) (0) | 2020.04.10 |