473,387 Members | 1,532 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,387 software developers and data experts.

datagrid view (or datagrid) to text file

hey, I'm using a windows form here,and I need to convert a datagridview
(actually its an Inragistics UltraGridView but whatever) to a text file. I
want each row to be in a single line.

I found plenty of tutorials online, but they are only for ASP, and they use
a stringwriter then they call upon System.Web.UI.HtmlTextWriter , and then
Response.write.

I've already got the grid loaded up in a stringbuilder, but how do I export
that stringbuilder to a text file??

here is my code if it will help:

DataSet DSToPrint = new DataSet();

//method returns populated dataset
DSToPrint = myClass.FillDataset();

//make a string builder
StringBuilder str = new StringBuilder();

//fill the string builder with all the rows in the dataset
for (int i = 0; i <= DSToPrint.Tables[0].Rows.Count - 1; i++)
{
for (int j = 0; j <= DSToPrint.Tables[0].Columns.Count - 1; j++)
{
str.Append("[" + DSToPrint.Tables[0].Rows[i][j].ToString() + "] ");
}
str.Append(Environment.NewLine);
}
now what??
thanks
Mar 22 '07 #1
2 4856
On Mar 22, 12:42 pm, roger_27 <roge...@discussions.microsoft.com>
wrote:
hey, I'm using a windows form here,and I need to convert a datagridview
(actually its an Inragistics UltraGridView but whatever) to a text file. I
want each row to be in a single line.

I found plenty of tutorials online, but they are only for ASP, and they use
a stringwriter then they call upon System.Web.UI.HtmlTextWriter , and then
Response.write.

I've already got the grid loaded up in a stringbuilder, but how do I export
that stringbuilder to a text file??

here is my code if it will help:

DataSet DSToPrint = new DataSet();

//method returns populated dataset
DSToPrint = myClass.FillDataset();

//make a string builder
StringBuilder str = new StringBuilder();

//fill the string builder with all the rows in the dataset
for (int i = 0; i <= DSToPrint.Tables[0].Rows.Count - 1; i++)
{
for (int j = 0; j <= DSToPrint.Tables[0].Columns.Count - 1; j++)
{
str.Append("[" + DSToPrint.Tables[0].Rows[i][j].ToString() + "] ");
}
str.Append(Environment.NewLine);

}

now what??
thanks
Are you looking for something like this?

System.IO.StreamWriter writer = new
System.IO.StreamWriter(aPath);
writer.Write(myString);
writer.Close();

--Rob W

Mar 22 '07 #2
awesome. rob you are the champion!!

"Rob Whiteside" wrote:
On Mar 22, 12:42 pm, roger_27 <roge...@discussions.microsoft.com>
wrote:
hey, I'm using a windows form here,and I need to convert a datagridview
(actually its an Inragistics UltraGridView but whatever) to a text file. I
want each row to be in a single line.

I found plenty of tutorials online, but they are only for ASP, and they use
a stringwriter then they call upon System.Web.UI.HtmlTextWriter , and then
Response.write.

I've already got the grid loaded up in a stringbuilder, but how do I export
that stringbuilder to a text file??

here is my code if it will help:

DataSet DSToPrint = new DataSet();

//method returns populated dataset
DSToPrint = myClass.FillDataset();

//make a string builder
StringBuilder str = new StringBuilder();

//fill the string builder with all the rows in the dataset
for (int i = 0; i <= DSToPrint.Tables[0].Rows.Count - 1; i++)
{
for (int j = 0; j <= DSToPrint.Tables[0].Columns.Count - 1; j++)
{
str.Append("[" + DSToPrint.Tables[0].Rows[i][j].ToString() + "] ");
}
str.Append(Environment.NewLine);

}

now what??
thanks

Are you looking for something like this?

System.IO.StreamWriter writer = new
System.IO.StreamWriter(aPath);
writer.Write(myString);
writer.Close();

--Rob W

Mar 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: footballhead | last post by:
I have a page with a datagrid that I have configured with all the information I need to provide to froogle for listing my products on their site. I am having trouble finding a way to successfully...
5
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
2
by: Bob | last post by:
I looked at the sample in the msdn january 2005 - Introducing a new datagrid, but the project downloaded failed to open. Any one can point me to a bit of code on how to go and select an image...
4
by: gordon | last post by:
Hi I hav e a smallish app that has a datagridview. A user can select some columns in the datagrid, and i have a button that i would like to use to copy the rows that are selected to the...
0
by: nanaalwi | last post by:
hi there, im doing a project right now to download a data from EEPROM of a camcorder. i used a 'data grid view' to display all the data downloaded from the camcorder. however, i have to save the...
1
by: =?Utf-8?B?UGF0cml4MzE3?= | last post by:
Caveat: newbie I would like to take the contents of the datagrid on my form and export it record by record to a flat text file. After some time searching, I came across two items: ...
2
by: aapy | last post by:
I am trying to write a logic where upon selection of a row it should fill the form based on the value of the row selected from the datagrid view... But it is giving "select one row" message only...
2
by: pragal | last post by:
Hi to all, I am new to php I am making a new web site, I want to display a table value in data grid view in a php page with edit and delete option for all values of the table. Please help me with...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.