T
TG
Hi!
This code works perfect except that it shows all the data from the
datagridview. I only want to export the columns that are visible.
How can I achieve this?
Thanks a lot!
Tammy
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim writer As StreamWriter = New StreamWriter("R:\Spam BB
Search Engine Application\Exports\GridExport.txt")
If (DataGridView1.Rows.Count > 0) Then
For Each col As DataGridViewColumn In
DataGridView1.Columns
If (col.Index = (DataGridView1.Columns.Count - 1))
Then
writer.WriteLine(col.HeaderText)
Else
writer.Write(String.Concat(col.HeaderText, ","))
End If
Next
For Each row As DataGridViewRow In DataGridView1.Rows
'If Not omitIndices.Contains(row.Index) Then
For Each cell As DataGridViewCell In row.Cells
If (cell.OwningColumn.Index _
= (DataGridView1.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
End If
writer.Close()
End Sub
This code works perfect except that it shows all the data from the
datagridview. I only want to export the columns that are visible.
How can I achieve this?
Thanks a lot!
Tammy
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim writer As StreamWriter = New StreamWriter("R:\Spam BB
Search Engine Application\Exports\GridExport.txt")
If (DataGridView1.Rows.Count > 0) Then
For Each col As DataGridViewColumn In
DataGridView1.Columns
If (col.Index = (DataGridView1.Columns.Count - 1))
Then
writer.WriteLine(col.HeaderText)
Else
writer.Write(String.Concat(col.HeaderText, ","))
End If
Next
For Each row As DataGridViewRow In DataGridView1.Rows
'If Not omitIndices.Contains(row.Index) Then
For Each cell As DataGridViewCell In row.Cells
If (cell.OwningColumn.Index _
= (DataGridView1.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
End If
writer.Close()
End Sub