Click here to Skip to main content
15,881,757 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# vs C++ process standard out redirection differences Pin
OriginalGriff23-Oct-22 8:16
mveOriginalGriff23-Oct-22 8:16 
QuestionLoading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie22-Oct-22 23:59
Ozzie Mozzie22-Oct-22 23:59 
AnswerRe: Loading a Data Table form a DataGrid view but still no joy. Pin
OriginalGriff23-Oct-22 0:51
mveOriginalGriff23-Oct-22 0:51 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie23-Oct-22 1:19
Ozzie Mozzie23-Oct-22 1:19 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
OriginalGriff23-Oct-22 1:46
mveOriginalGriff23-Oct-22 1:46 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie23-Oct-22 2:05
Ozzie Mozzie23-Oct-22 2:05 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
OriginalGriff23-Oct-22 2:37
mveOriginalGriff23-Oct-22 2:37 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie23-Oct-22 14:36
Ozzie Mozzie23-Oct-22 14:36 
Thank you for that bit of code as it does allow the saving of the original data table that was loaded from the file.
It, unfortunately, does not include any edits made to the DataGriview after the load.

What am I missing to update the DataTable so that it includes the changes made to the DataGridView?


private void saveToolStripMenuItem_Click(object sender, EventArgs e)
   {
       //      var dia = new System.Windows.Forms.SaveFileDialog();
       saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
       saveFileDialog1.Filter = "Excel Worksheets (*.xlsx)|*.xlsx|xls file (*.xls)|*.xls|All files (*.*)|*.*";
       saveFileDialog1.FileName = "";



       if (dataGridView1.DataSource is BindingSource SBind)   //bs)
       {
           if (SBind.DataSource is DataTable dataTable)
           {
               using (ExcelPackage package = new ExcelPackage())
               {
                   if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
                   {
                       try
                       {
                           ExcelWorksheet ws = package.Workbook.Worksheets.Add("Countries");
                           ws.Cells["A1"].LoadFromDataTable(dataTable, true);
                           package.SaveAs(new FileInfo(saveFileDialog1.FileName));
                       }
                       catch (Exception)
                       {
                           DialogResult reminder = MessageBox.Show("Cannot save file, file opened in another program.\nClose it first! ", "Save Failed", MessageBoxButtons.OK);
                       }
                   }
               }
           }
       }

   }

GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie23-Oct-22 16:03
Ozzie Mozzie23-Oct-22 16:03 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
OriginalGriff23-Oct-22 21:35
mveOriginalGriff23-Oct-22 21:35 
QuestionC# Save DataGrid Only MultiSelected Rows to File Pin
CodaNV22-Oct-22 17:03
CodaNV22-Oct-22 17:03 
AnswerRe: C# Save DataGrid Only MultiSelected Rows to File Pin
Dave Kreskowiak22-Oct-22 17:50
mveDave Kreskowiak22-Oct-22 17:50 
GeneralRe: C# Save DataGrid Only MultiSelected Rows to File Pin
CodaNV22-Oct-22 18:11
CodaNV22-Oct-22 18:11 
GeneralRe: C# Save DataGrid Only MultiSelected Rows to File Pin
Dave Kreskowiak22-Oct-22 18:24
mveDave Kreskowiak22-Oct-22 18:24 
GeneralRe: C# Save DataGrid Only MultiSelected Rows to File Pin
CodaNV22-Oct-22 18:47
CodaNV22-Oct-22 18:47 
QuestionArduino canot control computer. Pin
Member 1549382322-Oct-22 10:38
Member 1549382322-Oct-22 10:38 
AnswerRe: Arduino canot control computer. Pin
OriginalGriff22-Oct-22 10:53
mveOriginalGriff22-Oct-22 10:53 
QuestionReliable COM Port Communication Pin
Member 1495533221-Oct-22 1:36
Member 1495533221-Oct-22 1:36 
QuestionSimple Snake Game - Snake Head is not moving after ReadKey() Pin
Programmable Physics20-Oct-22 0:12
Programmable Physics20-Oct-22 0:12 
AnswerRe: Simple Snake Game - Snake Head is not moving after ReadKey() Pin
jsc4220-Oct-22 0:23
professionaljsc4220-Oct-22 0:23 
Questionget string from if statement in c# Pin
Sycho AN19-Oct-22 11:04
Sycho AN19-Oct-22 11:04 
AnswerRe: get string from if statement in c# Pin
OriginalGriff19-Oct-22 11:32
mveOriginalGriff19-Oct-22 11:32 
GeneralRe: get string from if statement in c# Pin
Sycho AN19-Oct-22 12:24
Sycho AN19-Oct-22 12:24 
GeneralRe: get string from if statement in c# Pin
Dave Kreskowiak19-Oct-22 12:33
mveDave Kreskowiak19-Oct-22 12:33 
AnswerRe: get string from if statement in c# Pin
Gerry Schmitz19-Oct-22 14:10
mveGerry Schmitz19-Oct-22 14:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.