我的帖子与Visual Basic Windows Forms程序有关。我有一个datagridview(称为:Device_LabelsDataGridView),它有一个可见和不可见的列放在一个对话框中。导出特定的DataGridView隐藏/可见列为TXT(不是整个DataGridView)
我想输出标题为“位置”(隐藏)和“数据”(可见)的特定两列,但错过了名为“说明”的中间列。出口下降我的数据是这样的(用逗号,就像它们是):
Location,Description,Data Location,Description,Data Location,Description,Data Continued…
但我想(再次,只因为他们是逗号)
Location,Data Location,Data Location,Data Continued…
下面是我的代码试图使用,但不能得到我想要的。
Dim writer As StreamWriter = New StreamWriter("C:\GridExport.txt")
If (DeviceLabels.Device_LabelsDataGridView.Rows.Count > 0) Then
For Each col As DataGridViewColumn In DeviceLabels.Device_LabelsDataGridView.Columns
Next
End If
For Each row As DataGridViewRow In DeviceLabels.Device_LabelsDataGridView.Rows
'If Not omitIndices.Contains(row.Index) Then
For Each cell As DataGridViewCell In row.Cells
If (cell.OwningColumn.Index = (DeviceLabels.Device_LabelsDataGridView.Columns.Count - 1)) Then
If (Not (cell.Value) Is Nothing) Then
writer.WriteLine(cell.Value.ToString)
Else
writer.WriteLine("")
End If
ElseIf (Not (cell.Value) Is Nothing) Then
writer.Write(String.Concat(cell.Value.ToString, ","))
Else
writer.Write(String.Concat("", ","))
End If
Next
'End If
Next
writer.Close()
End Sub
有人可以帮忙吗?我没有太多的头发了!我是VB的新手,有0经验,我也找不到任何相关示例,包括导出可见列和不可见列。
我也需要文本文件,所以不能使用其他格式。我正在创建的程序是一个EEPROM程序员。一旦这个文本导出工作,我可以在我的程序的下半部分工作 - 将文件发送到我的EEPROM处理程序。
就像我说我是一个初学者..我不知道你的代码甚至发布文本文件,或者它将保存它。那么这是用新列编辑我的datagridview吗? – user2355434 2013-05-06 22:36:03
对不起 - 我刚刚提供了部分解决方案的概述。很难发布一个完整的应用程序....我编辑了上述积累的行,然后将他们对一个文件。 – rheitzman 2013-05-07 19:35:35
你可以忽略我的DataGridView加载并使用你的DataGridView。删除对网格引用的DeviceLabels前缀。修改要在输出中包含哪些列的测试。 – rheitzman 2013-05-07 19:39:42