vb.net - 如何使用 CSV Datasource-VB.net 以另一种形式将 DataGridView 行移动到另一个 DataGridView
问题描述
我使用 CSV 从表单中的 DataGridView 加载数据和保存数据。我现在想要它,因此通过按钮单击事件,我可以将通过 DataGridView 上的复选框列选中的行发送到另一个以另一种形式托管的 dataGridView。
如果有帮助,这是我用来加载和保存 DataGridView 内容的负载。
Private Sub btnLoadDGVGeneral_Click(sender As Object, e As EventArgs) Handles btnLoadDGVGeneral.Click
' PURPOSE: Load CSV file containing tasks into DataGridView
' Clearing DGV Rows allows for Tasks to not double up when rebooting the program
dataGVGeneral.Rows.Clear()
'New Variable: fname, represents File Path of CSV as String
Dim fname As String = "E:\SAT\Work.io\Work.io\bin\Debug\ListofTasks.csv"
Dim reader As New StreamReader(fname, Encoding.Default)
Dim sline As String = ""
Dim colsexpected As Integer = 7
Dim r As Integer = 0
'StreamReader will the file Line by Line, and add it to the variable sline
'First sline statement is Out of Loop, as first line of CSV contains headings to what each figure represents in a line.
sline = reader.ReadLine
Do
'Now sline will read the 2nd line and so forth
sline = reader.ReadLine
'If no value is found on that line of the CSV file (at the end), then the loop will exit
If sline Is Nothing Then Exit Do
'Details is as a variable, which when called upon, places each value into different columns for that row
Dim details() As String = sline.Split(",")
dataGVGeneral.Rows.Add()
For i As Integer = 0 To 6
dataGVGeneral.Rows(r).Cells(i).Value = details(i)
Next
'Increments value of "r" by 1, meaning next line of CSV will be added to the next row.
Dim v As Integer = r + 1
r = v
Loop
reader.Close()
End Sub
Private Sub btnSaveGeneralDGV_Click(sender As Object, e As EventArgs) Handles btnSaveGeneralDGV.Click
Dim StrExport As String = ""
For Each C As DataGridViewColumn In dataGVGeneral.Columns
StrExport &= """" & C.HeaderText & ""","
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
For Each R As DataGridViewRow In dataGVGeneral.Rows
For Each C As DataGridViewCell In R.Cells
If Not C.Value Is Nothing Then
StrExport &= """" & C.Value.ToString & ""","
Else
StrExport &= """" & "" & ""","
End If
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
Next
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("E:\SAT\Work.io\Work.io\bin\Debug\ListofTasks.csv", False)
tw.Write(StrExport)
tw.Close()
End Sub
解决方案
推荐阅读
- google-bigquery - BigQuery - 如何根据数组元素对查询结果进行排序
- node.js - 在我的数据库中更改实体后,如何在 typeorm 中更新我的实体?
- python - 如何将密码添加到使用 pandas 数据框创建的 csv/excel
- android - 我需要一个命令从 selenium 的命令行打开 android 上的 chrome
- flutter - 编写涉及选择下拉菜单项的颤振测试
- sql - 如何从sql查询中json列中的json子字符串中检索信息
- javascript - 您可以在无需登录 Auth0 的情况下使用通用 MFA 进行嵌入式注册吗?
- r - 条件语句检查行 n AND n-1
- .net - .Net app.UseAuthorization() 阻止一些错误页面
- kubernetes - 活性探测失败:OCI 运行时执行失败:执行失败:EOF:未知