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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button5.Click
Dim writer As StreamWriter = New StreamWriter("R :\Spam BB
Search Engine Application\Exp orts\GridExport .txt")
If (DataGridView1. Rows.Count 0) Then
For Each col As DataGridViewCol umn In
DataGridView1.C olumns
If (col.Index = (DataGridView1. Columns.Count - 1))
Then
writer.WriteLin e(col.HeaderTex t)
Else
writer.Write(St ring.Concat(col .HeaderText, ","))
End If
Next
For Each row As DataGridViewRow In DataGridView1.R ows
'If Not omitIndices.Con tains(row.Index ) Then
For Each cell As DataGridViewCel l In row.Cells
If (cell.OwningCol umn.Index _
= (DataGridView1. Columns.Count - 1))
Then
If (Not (cell.Value) Is Nothing) Then
writer.WriteLin e(cell.Value.To String)
Else
writer.WriteLin e("")
End If
ElseIf (Not (cell.Value) Is Nothing) Then
writer.Write(St ring.Concat(cel l.Value.ToStrin g, ","))
Else
writer.Write(St ring.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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button5.Click
Dim writer As StreamWriter = New StreamWriter("R :\Spam BB
Search Engine Application\Exp orts\GridExport .txt")
If (DataGridView1. Rows.Count 0) Then
For Each col As DataGridViewCol umn In
DataGridView1.C olumns
If (col.Index = (DataGridView1. Columns.Count - 1))
Then
writer.WriteLin e(col.HeaderTex t)
Else
writer.Write(St ring.Concat(col .HeaderText, ","))
End If
Next
For Each row As DataGridViewRow In DataGridView1.R ows
'If Not omitIndices.Con tains(row.Index ) Then
For Each cell As DataGridViewCel l In row.Cells
If (cell.OwningCol umn.Index _
= (DataGridView1. Columns.Count - 1))
Then
If (Not (cell.Value) Is Nothing) Then
writer.WriteLin e(cell.Value.To String)
Else
writer.WriteLin e("")
End If
ElseIf (Not (cell.Value) Is Nothing) Then
writer.Write(St ring.Concat(cel l.Value.ToStrin g, ","))
Else
writer.Write(St ring.Concat("", ","))
End If
Next
'End If
Next
End If
writer.Close()
End Sub
Comment