mphillip85
asked on
Export Datagrid to CSV not Datagridview
Export DataGrid to CSV. I am trying to find the solution to a datagrid instead of a datagridview.
I am using vb .net 2003. I saw the datagridview code but I need a conversion of that to fit a datagrid only.
Thanks.
I am using vb .net 2003. I saw the datagridview code but I need a conversion of that to fit a datagrid only.
Thanks.
Have thought about iterating throw all the cells in the datagrid and generating a CSV manually?
ASKER
I am trying to have a function that I can just pass the datagrid name to and it does the rest. I basically know how to iterate through the rows and cells, but I cannot figure out how to find the column names and/or how many columns and/or how many rows. I can get the row count from the dataset that I gave as the datasource to the datagrid.
I just want to pass a few parameters and generate a CSV. I am having to do many datagrid reports, that I am trying to make a function call to achieve this.
I just want to pass a few parameters and generate a CSV. I am having to do many datagrid reports, that I am trying to make a function call to achieve this.
ok yeah thats a good idea. why not iterate through the dataset you are going to bind to the datagrid and generate the csv??
List<String> csvs = new List<String>();
for(int i=0; i < datatable.Rows.Count ; i++)
{
String rowcsv = "";
for(int columCounter = 0; columnCounter < dataTable.Rows[i].Cells.Co unt; columnCounter++)
{
rowcsv+= dataTable.Rows[i].Cells[co lumnCounte r].ToStrin g() + "'";
}
csvs.Add(rowcsv)
}
THis is the pseudo code of the function that takes a DataTable as input and returns a CSV array. Improvise on this with your requirements
List<String> csvs = new List<String>();
for(int i=0; i < datatable.Rows.Count ; i++)
{
String rowcsv = "";
for(int columCounter = 0; columnCounter < dataTable.Rows[i].Cells.Co
{
rowcsv+= dataTable.Rows[i].Cells[co
}
csvs.Add(rowcsv)
}
THis is the pseudo code of the function that takes a DataTable as input and returns a CSV array. Improvise on this with your requirements
ASKER
I would use the dataset except that I do not use all the columns in the dataset to display. Or else I would have 10 times the datasets I needed to do everything. I need to just export only what is displayed in the datagrid. Or else I would have used the dataset and made calls to find the columns and etc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.