commit 9419eeda763a2a6d6db98b0cc12027b6e04699ae Author: Eugen Höglinger Date: Tue Apr 23 15:10:22 2024 +0200 Initialize diff --git a/.vs/Test_TabControlsAndDataGridViews.git/FileContentIndex/52dc4549-47f8-4883-a33a-1c7313a5d2f6.vsidx b/.vs/Test_TabControlsAndDataGridViews.git/FileContentIndex/52dc4549-47f8-4883-a33a-1c7313a5d2f6.vsidx new file mode 100644 index 0000000..fca6a68 Binary files /dev/null and b/.vs/Test_TabControlsAndDataGridViews.git/FileContentIndex/52dc4549-47f8-4883-a33a-1c7313a5d2f6.vsidx differ diff --git a/.vs/Test_TabControlsAndDataGridViews.git/v17/.suo b/.vs/Test_TabControlsAndDataGridViews.git/v17/.suo new file mode 100644 index 0000000..a137193 Binary files /dev/null and b/.vs/Test_TabControlsAndDataGridViews.git/v17/.suo differ diff --git a/.vs/Test_TabControlsAndDataGridViews.git/v17/DocumentLayout.json b/.vs/Test_TabControlsAndDataGridViews.git/v17/DocumentLayout.json new file mode 100644 index 0000000..e75ec07 --- /dev/null +++ b/.vs/Test_TabControlsAndDataGridViews.git/v17/DocumentLayout.json @@ -0,0 +1,65 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\CAD\\Git-WorkRepository\\VisualStudio\\_TEST\\Test_TabControlsAndDataGridViews.git\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}|Test_TabControlsAndDataGridViews\\Test_TabControlsAndDataGridViews.csproj|C:\\CAD\\Git-WorkRepository\\VisualStudio\\_TEST\\Test_TabControlsAndDataGridViews.git\\test_tabcontrolsanddatagridviews\\form1.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form", + "RelativeMoniker": "D:0:0:{5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}|Test_TabControlsAndDataGridViews\\Test_TabControlsAndDataGridViews.csproj|solutionrelative:test_tabcontrolsanddatagridviews\\form1.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form" + }, + { + "AbsoluteMoniker": "D:0:0:{5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}|Test_TabControlsAndDataGridViews\\Test_TabControlsAndDataGridViews.csproj|c:\\cad\\git-workrepository\\visualstudio\\_test\\test_tabcontrolsanddatagridviews.git\\test_tabcontrolsanddatagridviews\\form1.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}|Test_TabControlsAndDataGridViews\\Test_TabControlsAndDataGridViews.csproj|solutionrelative:test_tabcontrolsanddatagridviews\\form1.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 4, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}" + }, + { + "$type": "Bookmark", + "Name": "ST:129:0:{1fc202d4-d401-403c-9834-5b218574bb67}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{e506b91c-c606-466a-90a9-123d1d1e12b3}" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "Form1.cs", + "DocumentMoniker": "C:\\CAD\\Git-WorkRepository\\VisualStudio\\_TEST\\Test_TabControlsAndDataGridViews.git\\Test_TabControlsAndDataGridViews\\Form1.cs", + "RelativeDocumentMoniker": "Test_TabControlsAndDataGridViews\\Form1.cs", + "ToolTip": "C:\\CAD\\Git-WorkRepository\\VisualStudio\\_TEST\\Test_TabControlsAndDataGridViews.git\\Test_TabControlsAndDataGridViews\\Form1.cs", + "RelativeToolTip": "Test_TabControlsAndDataGridViews\\Form1.cs", + "ViewState": "AQIAAAAAAAAAAAAAAAAAAIIAAABIAAAA", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2024-04-16T12:52:38.812Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "Form1.cs [Entwurf]", + "DocumentMoniker": "C:\\CAD\\Git-WorkRepository\\VisualStudio\\_TEST\\Test_TabControlsAndDataGridViews.git\\Test_TabControlsAndDataGridViews\\Form1.cs", + "RelativeDocumentMoniker": "Test_TabControlsAndDataGridViews\\Form1.cs", + "ToolTip": "C:\\CAD\\Git-WorkRepository\\VisualStudio\\_TEST\\Test_TabControlsAndDataGridViews.git\\Test_TabControlsAndDataGridViews\\Form1.cs [Entwurf]", + "RelativeToolTip": "Test_TabControlsAndDataGridViews\\Form1.cs [Entwurf]", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2024-04-16T12:52:35.365Z", + "EditorCaption": " [Entwurf]" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Daten/CD 1/File 1.txt b/Daten/CD 1/File 1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Daten/CD 2/File 2.txt b/Daten/CD 2/File 2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Daten/CD 3/File 3.txt b/Daten/CD 3/File 3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Daten/CD 4/File 4.txt b/Daten/CD 4/File 4.txt new file mode 100644 index 0000000..e69de29 diff --git a/Test_TabControlsAndDataGridViews.git.sln b/Test_TabControlsAndDataGridViews.git.sln new file mode 100644 index 0000000..3c003c2 --- /dev/null +++ b/Test_TabControlsAndDataGridViews.git.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34723.18 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_TabControlsAndDataGridViews", "Test_TabControlsAndDataGridViews\Test_TabControlsAndDataGridViews.csproj", "{5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EE0AAE3B-24EC-4C45-B100-83F466A368BB} + EndGlobalSection +EndGlobal diff --git a/Test_TabControlsAndDataGridViews/App.config b/Test_TabControlsAndDataGridViews/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test_TabControlsAndDataGridViews/Form1.Designer.cs b/Test_TabControlsAndDataGridViews/Form1.Designer.cs new file mode 100644 index 0000000..ab7f8f1 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Form1.Designer.cs @@ -0,0 +1,114 @@ +namespace Test_TabControlsAndDataGridViews +{ + partial class Form1 + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.buttonAddTab = new System.Windows.Forms.Button(); + this.buttonRemoveTab = new System.Windows.Forms.Button(); + this.buttonRemoveSelectedTab = new System.Windows.Forms.Button(); + this.buttonMoveTabToLeft = new System.Windows.Forms.Button(); + this.buttonMoveTabToRight = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // buttonAddTab + // + this.buttonAddTab.Location = new System.Drawing.Point(13, 415); + this.buttonAddTab.Name = "buttonAddTab"; + this.buttonAddTab.Size = new System.Drawing.Size(129, 23); + this.buttonAddTab.TabIndex = 0; + this.buttonAddTab.Text = "Add Tab"; + this.buttonAddTab.UseVisualStyleBackColor = true; + this.buttonAddTab.Click += new System.EventHandler(this.buttonAddTab_Click); + // + // buttonRemoveTab + // + this.buttonRemoveTab.Location = new System.Drawing.Point(174, 415); + this.buttonRemoveTab.Name = "buttonRemoveTab"; + this.buttonRemoveTab.Size = new System.Drawing.Size(129, 23); + this.buttonRemoveTab.TabIndex = 1; + this.buttonRemoveTab.Text = "Remove Tab"; + this.buttonRemoveTab.UseVisualStyleBackColor = true; + this.buttonRemoveTab.Click += new System.EventHandler(this.buttonRemoveTab_Click); + // + // buttonRemoveSelectedTab + // + this.buttonRemoveSelectedTab.Location = new System.Drawing.Point(335, 415); + this.buttonRemoveSelectedTab.Name = "buttonRemoveSelectedTab"; + this.buttonRemoveSelectedTab.Size = new System.Drawing.Size(129, 23); + this.buttonRemoveSelectedTab.TabIndex = 2; + this.buttonRemoveSelectedTab.Text = "Remove Selected Tab"; + this.buttonRemoveSelectedTab.UseVisualStyleBackColor = true; + this.buttonRemoveSelectedTab.Click += new System.EventHandler(this.buttonRemoveSelectedTab_Click); + // + // buttonMoveTabToLeft + // + this.buttonMoveTabToLeft.Location = new System.Drawing.Point(496, 415); + this.buttonMoveTabToLeft.Name = "buttonMoveTabToLeft"; + this.buttonMoveTabToLeft.Size = new System.Drawing.Size(129, 23); + this.buttonMoveTabToLeft.TabIndex = 3; + this.buttonMoveTabToLeft.Text = "Tab nach links"; + this.buttonMoveTabToLeft.UseVisualStyleBackColor = true; + this.buttonMoveTabToLeft.Click += new System.EventHandler(this.buttonMoveTabToLeft_Click); + // + // buttonMoveTabToRight + // + this.buttonMoveTabToRight.Location = new System.Drawing.Point(657, 415); + this.buttonMoveTabToRight.Name = "buttonMoveTabToRight"; + this.buttonMoveTabToRight.Size = new System.Drawing.Size(129, 23); + this.buttonMoveTabToRight.TabIndex = 4; + this.buttonMoveTabToRight.Text = "Tab nach rechts"; + this.buttonMoveTabToRight.UseVisualStyleBackColor = true; + this.buttonMoveTabToRight.Click += new System.EventHandler(this.buttonMoveTabToRight_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonMoveTabToRight); + this.Controls.Add(this.buttonMoveTabToLeft); + this.Controls.Add(this.buttonRemoveSelectedTab); + this.Controls.Add(this.buttonRemoveTab); + this.Controls.Add(this.buttonAddTab); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button buttonAddTab; + private System.Windows.Forms.Button buttonRemoveTab; + private System.Windows.Forms.Button buttonRemoveSelectedTab; + private System.Windows.Forms.Button buttonMoveTabToLeft; + private System.Windows.Forms.Button buttonMoveTabToRight; + } +} + diff --git a/Test_TabControlsAndDataGridViews/Form1.cs b/Test_TabControlsAndDataGridViews/Form1.cs new file mode 100644 index 0000000..8a94096 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Form1.cs @@ -0,0 +1,418 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Net.WebRequestMethods; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar; + +namespace Test_TabControlsAndDataGridViews +{ + public partial class Form1 : Form + { + #region Version und Copyright + // Version und Copyright + string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen + string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); + string copyright = GenerateCopyright(); + string icon = Application.StartupPath + "\\Info.bmp"; + + //Assembly Datum und Zeit + static DateTime value = AssemblyDateTime(); + string date = value.ToShortDateString(); + string time = value.ToLongTimeString(); + + private static DateTime AssemblyDateTime() + { + var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision)); + //Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original) + return buildDateTime; + } + + private static string CurrentYear() + { + DateTime dtn = DateTime.Now; + return dtn.Year.ToString(); + } + + private static string StartYear() + { + string startYear = ""; + if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © ")) + { + startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", ""); + while (startYear.StartsWith(" ")) + { + startYear = startYear.Remove(0, 1); + } + + if (startYear.Contains("-")) + { + startYear = startYear.Remove(startYear.IndexOf("-")); + } + else + { + startYear = startYear.Remove(startYear.IndexOf(" ")); + } + return startYear; + } + else + { + DateTime dtn = DateTime.Now; + return dtn.Year.ToString(); + } + } + + private static string GenerateCopyright() + { + string startYear = StartYear(); + string currentYear = CurrentYear(); + + if (startYear == currentYear) + { + return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + } + else + { + string temp = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + string start = temp.Remove(temp.IndexOf(startYear) - 1); + string end = (temp.Remove(0, temp.IndexOf(" by"))); + + return String.Concat(start, " ", startYear, "-", currentYear, end); + } + } + #endregion + + #region Programm-Info + /// + /// Contains the name of the program file + /// + public static string ProgramName { set; get; } + + /// + /// Contains the version of the program file + /// + public static string ProgramVersion { set; get; } + + /// + /// Contains the copyright notice + /// + public static string Copyright { set; get; } + + private void SetProgramInfo() + { + //Name, Version und Copyright setzen + ProgramName = programName; + ProgramVersion = programVersion; + Copyright = copyright; + } + #endregion + public Form1() + { + SetProgramInfo(); + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + CreatingTabControl(); + } + + TabControl DynamicTabControl { set; get; } // Current TabControl + List DataGridViewValues { get; set; } + List PreviousDataGridViewValues { get; set; } + List NextDataGridViewValues { get; set; } + + int maxNumbersOfTabPages = 12; + + private void CreatingTabControl() + { + // Create a TabControl and set its properties + TabControl dynamicTabControl = new TabControl(); + dynamicTabControl.Name = "DynamicTabControl"; + //dynamicTabControl.BackColor = Color.White; + //dynamicTabControl.ForeColor = Color.Black; + //dynamicTabControl.Font = new Font("Arial", 10); + dynamicTabControl.Width = 700; + dynamicTabControl.Height = 400; + Controls.Add(dynamicTabControl); // Add TabControl to Form + + // Add TabPage with DataGridView to TabControl + AddTabPageWithDataGridView(dynamicTabControl); + + // Speichert das aktuelle TabControl + DynamicTabControl = dynamicTabControl; + } + + private void AddTabPage(TabControl dynamicTabControl, int count) + { + TabPage tabPage = new TabPage(); + tabPage.Name = "tabPage" + count.ToString(); + tabPage.Text = "Tab " + count.ToString(); + dynamicTabControl.TabPages.Add(tabPage); + } + + private void AddDataGridViewTable(TabControl dynamicTabControl, int number) + { + DataGridView dataGridView = new DataGridView(); + + this.Controls.Add(dataGridView); + + dataGridView.ColumnCount = 2; + dataGridView.Name = "dataGridView" + number.ToString(); + dataGridView.Columns[0].Name = "Number"; + dataGridView.Columns[1].Name = "Title"; + dataGridView.Columns[0].Width = 50; + dataGridView.Columns[1].Width = 599; + dataGridView.ScrollBars = ScrollBars.Both; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Rows.Add(); + + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.MultiSelect = false; + + dynamicTabControl.TabPages[number].Controls.Add(dataGridView); + } + + private void AddTabPageWithDataGridView(TabControl dynamicTabControl) + { + int numberOfTabs = dynamicTabControl.TabCount; + + if (numberOfTabs < maxNumbersOfTabPages) + { + AddTabPage(dynamicTabControl, numberOfTabs); // Add TabPage to TabControl + AddDataGridViewTable(dynamicTabControl, numberOfTabs); // Add a separate DataGridView for each TabPage + } + } + + private void RemoveTabPage(TabControl dynamicTabControl) + { + // Removes the last 'TabControl' + + // There must be at least 2 'TabControl', so that one can be removed + if (dynamicTabControl.TabCount > 1) + { + TabPage tab = dynamicTabControl.TabPages[dynamicTabControl.TabCount - 1]; + + // There must be at least 2 'TabControl', so that one can be removed + if (dynamicTabControl.TabCount > 1) + { + // As long as the 'TabControl' (DataGridView) contains data, it cannot be deleted + if (IsDataGridViewEmpty(tab.Controls.OfType().FirstOrDefault())) + { + dynamicTabControl.TabPages.Remove(tab); + } + else + { + MessageBox.Show("Löschen nicht möglich!\n\r\n\rTab kann nicht gelöscht werden,\n\rweil die Tabelle noch Daten enthälten!\n\r"); + } + } + } + } + + private void RemoveSelectedTabPage(TabControl dynamicTabControl) + { + // Removes the selected 'TabControl' + + // There must be at least 2 'TabControl', so that one can be removed + if (dynamicTabControl.TabCount > 1) + { + // As long as the 'TabControl' (DataGridView) contains data, it cannot be deleted + if (IsDataGridViewEmpty(dynamicTabControl.SelectedTab.Controls.OfType().FirstOrDefault())) + { + dynamicTabControl.TabPages.Remove(dynamicTabControl.SelectedTab); + } + else + { + MessageBox.Show("Löschen nicht möglich!\n\r\n\rTab kann nicht gelöscht werden,\n\rweil die Tabelle noch Daten enthälten!\n\r"); + } + + RenameTabs(dynamicTabControl); // Rename all 'TabControl' so that they are numbered consecutively again + } + } + + private void RenameTabs(TabControl dynamicTabControl) + { + // Rename all 'TabControl' so that they are numbered consecutively again + for (int i = 0; i < dynamicTabControl.TabCount; i++) + { + dynamicTabControl.TabPages[i].Name = "tabPage" + i.ToString(); + dynamicTabControl.TabPages[i].Text = "Tab " + i.ToString(); + } + } + + private bool IsDataGridViewEmpty(DataGridView dataGridView) + { + bool isEmpty = true; + + if (dataGridView.Rows.Count == 0) + { + isEmpty = true; //Wenn es keine Zeilen gibt, dann ist die Tabelle leer + } + else + { + //Wenn es Zeilen gibt ... + for (int i = 0; i < dataGridView.Rows.Count; i++) + { + for (int j = 0; j < dataGridView.Columns.Count; j++) + { + if (dataGridView[j, i].Value != null) + { + isEmpty = false; //... und die Zelle nicht leer ist, dann ist die Tabelle nicht leer + } + } + } + } + + return isEmpty; + } + + private void MoveTabToLeft(TabControl dynamicTabControl, DataGridView dataGridView) + { + // Moves the selected 'TabPage' to the left and renumber/rename the others + + int index = dynamicTabControl.SelectedIndex; // The index of the selected 'TabPage' + + // If there is more than one 'TabPage', then move to the left + if (index > 0) + { + DataGridViewValues = DetermineDataGridViewValues(dynamicTabControl, dataGridView); // Write all values from the selected dataGridView to a list + + TabControl PreviousTabControl = DeterminePreviousControl(DynamicTabControl); // Change the control to the previous 'TabPage' + + DataGridView previousDataGridView = PreviousTabControl.SelectedTab.Controls.OfType().FirstOrDefault(); // Chang the control to the previous dataGridView + PreviousDataGridViewValues = DetermineDataGridViewValues(PreviousTabControl, previousDataGridView); // Write all values from the previous dataGridView to a list + + WriteDataGridView(previousDataGridView, DataGridViewValues); // Write the data from the selected dataGridView back to the previous dataGridView + + dynamicTabControl.SelectedIndex = index; //Set the selected 'TabPage' as current 'TabPage' + WriteDataGridView(dataGridView, PreviousDataGridViewValues); // Write the data from the previous dataGridView back to the selected dataGridView + + PreviousTabControl = DeterminePreviousControl(DynamicTabControl); // Change the control to the previous 'TabPage' + } + + //TODO: Rename folders + } + + private void MoveTabToRight(TabControl dynamicTabControl, DataGridView dataGridView) + { + // Moves the selected 'TabPage' to the right and renumber/rename the others + + int index = dynamicTabControl.SelectedIndex; // The index of the selected 'TabPage' + + // If the selected tab is not the last tab, then move it to the right + if (index < dynamicTabControl.TabCount) + { + // TODO: If the selected tab is not the last tab, then move it to the right + DataGridViewValues = DetermineDataGridViewValues(dynamicTabControl, dataGridView); // Write all values from the selected dataGridView to a list + + TabControl NextTabControl = DetermineNextControl(DynamicTabControl); // Change the control to the next 'TabPage' + + DataGridView nextDataGridView = NextTabControl.SelectedTab.Controls.OfType().FirstOrDefault(); // Chang the control to the next dataGridView + NextDataGridViewValues = DetermineDataGridViewValues(NextTabControl, nextDataGridView); // Write all values from the next dataGridView to a list + + WriteDataGridView(nextDataGridView, DataGridViewValues); // Write the data from the selected dataGridView back to the next dataGridView + + dynamicTabControl.SelectedIndex = index; //Set the selected 'TabPage' as current 'TabPage' + WriteDataGridView(dataGridView, NextDataGridViewValues); // Write the data from the next dataGridView back to the selected dataGridView + + NextTabControl = DetermineNextControl(DynamicTabControl); // Change the control to the next 'TabPage' + } + + //TODO: Rename folders + } + + private TabControl DeterminePreviousControl(TabControl dynamicTabControl) + { + dynamicTabControl.SelectedIndex = dynamicTabControl.SelectedIndex - 1; + return dynamicTabControl; + } + + private TabControl DetermineNextControl(TabControl dynamicTabControl) + { + dynamicTabControl.SelectedIndex = dynamicTabControl.SelectedIndex + 1; + return dynamicTabControl; + } + + private List DetermineDataGridViewValues(TabControl dynamicTabControl, DataGridView dataGridView) + { + string[] rowValues = new string[2]; + List dataGridViewValues = new List(); + + // Werte der DataGridview einlesen + for (int i = 0; i < dataGridView.Rows.Count - 1; i++) + { + if (dataGridView[0, i].Value == null) + { + rowValues[0] = ""; + } + else + { + rowValues[0] = dataGridView[0, i].Value.ToString(); + } + + if (dataGridView[0, i].Value == null) + { + rowValues[1] = ""; + } + else + { + rowValues[1] = dataGridView[1, i].Value.ToString(); + } + + dataGridViewValues.Add(rowValues); + } + + return dataGridViewValues; + } + + private void WriteDataGridView(DataGridView dataGridView, List dataGridViewValues) + { + dataGridView.Rows.Clear(); // Delete all existing values + + for (int i = 0; i < dataGridViewValues.Count; i++) + { + dataGridView.Rows.Add(); + dataGridView[0, i].Value = dataGridViewValues[i].GetValue(0); + dataGridView[1, i].Value = dataGridViewValues[i].GetValue(1); + } + + dataGridView.Refresh(); + } + + private void buttonAddTab_Click(object sender, EventArgs e) + { + AddTabPageWithDataGridView(DynamicTabControl); + } + + private void buttonRemoveTab_Click(object sender, EventArgs e) + { + RemoveTabPage(DynamicTabControl); // Removes the last 'TabPage' + } + + private void buttonRemoveSelectedTab_Click(object sender, EventArgs e) + { + RemoveSelectedTabPage(DynamicTabControl); // Removes the selected 'TabPage' and renumber/rename the others + } + + private void buttonMoveTabToLeft_Click(object sender, EventArgs e) + { + MoveTabToLeft(DynamicTabControl, DynamicTabControl.SelectedTab.Controls.OfType().FirstOrDefault()); // Moves the selected 'TabPage' to the left and renumber/rename the others + } + + private void buttonMoveTabToRight_Click(object sender, EventArgs e) + { + MoveTabToRight(DynamicTabControl, DynamicTabControl.SelectedTab.Controls.OfType().FirstOrDefault()); // Moves the selected 'TabPage' to the rigth and renumber/rename the others + } + } +} diff --git a/Test_TabControlsAndDataGridViews/Form1.resx b/Test_TabControlsAndDataGridViews/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Test_TabControlsAndDataGridViews/Program.cs b/Test_TabControlsAndDataGridViews/Program.cs new file mode 100644 index 0000000..d2d8246 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Test_TabControlsAndDataGridViews +{ + internal static class Program + { + /// + /// Der Haupteinstiegspunkt für die Anwendung. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Test_TabControlsAndDataGridViews/Properties/AssemblyInfo.cs b/Test_TabControlsAndDataGridViews/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2f9d363 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Test_TabControlsAndDataGridViews")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Test_TabControlsAndDataGridViews")] +[assembly: AssemblyCopyright("Copyright © 2024 by Eugen Höglinger")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("5780cb23-8abe-4dce-95fc-bc35f4ecc14b")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.*")] +//[assembly: AssemblyFileVersion("1.0.0.0")] //Wenn auskommentiert, dann gleich wie AssemblyVersion! diff --git a/Test_TabControlsAndDataGridViews/Properties/Resources.Designer.cs b/Test_TabControlsAndDataGridViews/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6772edb --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion: 4.0.30319.42000 +// +// Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn +// der Code neu generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Test_TabControsAndDataGridViews.Properties +{ + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder-Klasse + // über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der Option /str erneut aus, oder erstellen Sie Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test_TabControsAndDataGridViews.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenlookups, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Test_TabControlsAndDataGridViews/Properties/Resources.resx b/Test_TabControlsAndDataGridViews/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Test_TabControlsAndDataGridViews/Properties/Settings.Designer.cs b/Test_TabControlsAndDataGridViews/Properties/Settings.Designer.cs new file mode 100644 index 0000000..c0481f3 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Test_TabControsAndDataGridViews.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Test_TabControlsAndDataGridViews/Properties/Settings.settings b/Test_TabControlsAndDataGridViews/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Test_TabControlsAndDataGridViews/Test_TabControlsAndDataGridViews.csproj b/Test_TabControlsAndDataGridViews/Test_TabControlsAndDataGridViews.csproj new file mode 100644 index 0000000..feb05ba --- /dev/null +++ b/Test_TabControlsAndDataGridViews/Test_TabControlsAndDataGridViews.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {5780CB23-8ABE-4DCE-95FC-BC35F4ECC14B} + WinExe + Test_TabControlsAndDataGridViews + Test_TabControlsAndDataGridViews + v4.7.2 + 512 + true + false + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.exe b/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.exe new file mode 100644 index 0000000..912d037 Binary files /dev/null and b/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.exe differ diff --git a/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.exe.config b/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.exe.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.pdb b/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.pdb new file mode 100644 index 0000000..d76ab2f Binary files /dev/null and b/Test_TabControlsAndDataGridViews/bin/Debug/Test_TabControlsAndDataGridViews.pdb differ diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs b/Test_TabControlsAndDataGridViews/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs new file mode 100644 index 0000000..3871b18 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/Test_TabControlsAndDataGridViews/obj/Debug/DesignTimeResolveAssemblyReferences.cache new file mode 100644 index 0000000..2d21f8d Binary files /dev/null and b/Test_TabControlsAndDataGridViews/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Test_TabControlsAndDataGridViews/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..3e640f5 Binary files /dev/null and b/Test_TabControlsAndDataGridViews/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.Form1.resources b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.Form1.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.Form1.resources differ diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.Properties.Resources.resources b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.Properties.Resources.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.Properties.Resources.resources differ diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.AssemblyReference.cache b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.AssemblyReference.cache new file mode 100644 index 0000000..825f721 Binary files /dev/null and b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.AssemblyReference.cache differ diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.CoreCompileInputs.cache b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..cf6f1c0 --- /dev/null +++ b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +ffeb981a72357c13c78580d1de8dfcfdeab69b3831ebd504970e578b1a834c6f diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.FileListAbsolute.txt b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..78f9d3e --- /dev/null +++ b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.FileListAbsolute.txt @@ -0,0 +1,10 @@ +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\bin\Debug\Test_TabControlsAndDataGridViews.exe.config +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\bin\Debug\Test_TabControlsAndDataGridViews.exe +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\bin\Debug\Test_TabControlsAndDataGridViews.pdb +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\obj\Debug\Test_TabControlsAndDataGridViews.csproj.AssemblyReference.cache +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\obj\Debug\Test_TabControlsAndDataGridViews.Form1.resources +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\obj\Debug\Test_TabControlsAndDataGridViews.Properties.Resources.resources +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\obj\Debug\Test_TabControlsAndDataGridViews.csproj.GenerateResource.cache +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\obj\Debug\Test_TabControlsAndDataGridViews.csproj.CoreCompileInputs.cache +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\obj\Debug\Test_TabControlsAndDataGridViews.exe +C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_TabControlsAndDataGridViews.git\Test_TabControlsAndDataGridViews\obj\Debug\Test_TabControlsAndDataGridViews.pdb diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.GenerateResource.cache b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.GenerateResource.cache new file mode 100644 index 0000000..eda00c5 Binary files /dev/null and b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.csproj.GenerateResource.cache differ diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.exe b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.exe new file mode 100644 index 0000000..912d037 Binary files /dev/null and b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.exe differ diff --git a/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.pdb b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.pdb new file mode 100644 index 0000000..d76ab2f Binary files /dev/null and b/Test_TabControlsAndDataGridViews/obj/Debug/Test_TabControlsAndDataGridViews.pdb differ