I have a Windows App that analyzes some data an displays some summary information to a text box. I would like to be able to send the detailed information to an Excel file. The button is visible and ready to be clicked. The Excel helper is ready to be used. How can I send the data table to the button click method? The Data Table is local to the "analyzer" method.
The code is structured as follows:
User enters necessary filters and clicks the "Analyze Data" button
private void btn_AnalyzeData_Click(object sender, EventArgs e)
{
//Do all kinds of analysis
DataTable dtInfo = new DataTable();
BuildTableHeaders(dtInfo);
PopulateDataTable(dtInfo);
string[,] strInfo = PopulateStrInfo(dtInfo);
//Display String
dtInfo.Dispose();
}
The user looks at the display and thinks "interesting, I had better look at the detail" and hits the "Send to Excel" button.
private void btn_SendToExcel_Click(object sender, EventArgs e)
{
------Do not know what to do here???
------Since dtInfo is local to the above event I do not know how to pass it to this event
ExcelHelper.CreateXLFile(dtInfo);
}
Thank you.
Rod
Loading
SenthilkumarPosted Mar 27, 2012, 11:53 PM
You can declare DataSet as global and load the dataset in the Analyse Data click. If you click on the SendToExcel button then you can get the value from the DataSet.
You know that the dataset value will be only filled when click on analyse data then enable the SendToExcel button. Use the dataset that already filled in the analyse data click event.