473,385 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Exporting a datagridview to .csv

jamesd0142
469 256MB
Hey how do i go about exporting the contents of a datagridview to a .csv file.

can any point me in the right way?

Thanks
Dec 17 '07 #1
2 3002
debasisdas
8,127 Expert 4TB
How you are polulating the datagrid ?
Dec 17 '07 #2
jamesd0142
469 256MB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Write(ByVal header As String)
  2.         Dim objStreamWriter As IO.StreamWriter
  3.  
  4.         'Pass the file path and the file name to the StreamWriter
  5.         'constructor.
  6.         'make sure this is a path that you have permissions to save in
  7.  
  8.         objStreamWriter = New IO.StreamWriter(txtPath.Text)
  9.         'Write text.
  10.  
  11.         Dim Str As String
  12.         Dim i As Integer
  13.         Dim j As Integer
  14.  
  15.         Dim headertext = header
  16.         objStreamWriter.WriteLine(headertext)
  17.         For i = 0 To (Me.DGV1.Rows.Count - 2)
  18.             For j = 0 To (Me.DGV1.Columns.Count - 1)
  19.                 'this IF statement stops it from adding a comma after
  20.                 'the last field
  21.                 If j = (Me.DGV1.Columns.Count - 1) Then
  22.                     Str = (Me.DGV1.Rows(i).Cells(j).Value.ToString)
  23.                 Else
  24.                     Str = (Me.DGV1.Rows(i).Cells(j).Value.ToString & ",")    '(Me.DGV1.Rows(i).Cells(j).Text.ToString & ",")
  25.                 End If
  26.                 objStreamWriter.Write(Str)
  27.             Next
  28.             objStreamWriter.WriteLine()
  29.         Next
  30.         'Close the file.
  31.         objStreamWriter.Close()
  32.     End Sub
  33.  
thats the solution i have used... thanks
Dec 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
1
by: michaeleaton | last post by:
Evening. I have an unbound dataGridView which i'm populating programatically (not using a dataset) from xml/user entered data. What i now need to do is when the user clicks save i want it to write...
1
by: bungle | last post by:
Hi Does anyone have any suggestions for exporting a datagridview which includes graphics to excel? I know it is relatively simple to do a normal export, but the fact that I have images in the...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
2
Lokean
by: Lokean | last post by:
I have a function that exports the DGview to excel one cell at a time, it gets the job done, but not very quickly. Is there a way to export a datagridview's contents to Excel in a way other than...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
1
by: jgabrielson | last post by:
Hello All, I have a windows application that exports data from a datagridview into excel. Now this data can change based on what a user does in the datagridview itself. An example would be out of...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.