-
Jun 26th, 2020, 03:53 PM
#1
Thread Starter
New Member
export datagrid to csv
good evening.
vineyard ask for help how can i export custom columns and only the checked rows from a datagridview to csv
-
Jun 26th, 2020, 04:42 PM
#2
Re: export datagrid to csv
hello,
have a look here and here, you may find ideas and tips
Regards
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Jun 27th, 2020, 06:08 AM
#3
Re: export datagrid to csv
If you want to export all columns excluding the check column see the following.
https://gist.github.com/karenpayneor...aae17bdbce33b7
This will not handle partial column list.
-
Jun 27th, 2020, 07:27 AM
#4
Re: export datagrid to csv
Originally Posted by bsande
good evening.
vineyard ask for help how can i export custom columns and only the checked rows from a datagridview to csv
you didn't show how you load the Datagridview
you could pass a Datatable to a DataSet
then pick out the Columns
Code:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
CSVExport("E:\TestFolder\xChris.csv", _
dset.Tables(0), _
New DataColumn() _
{dset.Tables(0).Columns(0), _
dset.Tables(0).Columns(2)})
End Sub
Private Sub CSVExport(ByVal filename As String, _
ByVal table As DataTable, _
ByVal cols As DataColumn())
Dim sw As New IO.StreamWriter(filename)
For Each drow As DataRow In table.Rows
For i As Integer = 0 To cols.GetUpperBound(0)
sw.Write(drow(cols(i)).ToString & ";")
Next
sw.WriteLine()
Next
sw.Close()
End Sub
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Jun 28th, 2020, 01:51 PM
#5
Re: export datagrid to csv
Try this...
Code:
Dim contents As String = ""
For r As Integer = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(r).IsNewRow Then Continue For
If CBool(DataGridView1.Rows(r).Cells(yourCheckBoxComnIndex).Value) = True Then
For c As Integer = 0 To DataGridView1.ColumnCount - 1
If c < DataGridView1.ColumnCount - 1 Then
contents &= If(DataGridView1.Rows(r).Cells(c).Value IsNot Nothing, DataGridView1.Rows(r).Cells(c).Value.ToString, "") & ","
Else
contents &= If(DataGridView1.Rows(r).Cells(c).Value IsNot Nothing, DataGridView1.Rows(r).Cells(c).Value.ToString, "") & vbCrLf
End If
Next
End If
Next
IO.File.WriteAllText("yourFilename.csv", contents)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|