Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamically adding tabs
    primarykey
    data
    text
    <p>I want to add tabs dynamically during the runtime. </p> <p>I made a own class for the tabs like this:</p> <pre><code>namespace Demo { public partial class Tabs : UserControl { private static DateTime ArrivalStart; public static DateTime arrivalStart { get { return ArrivalStart; } set { ArrivalStart = value; } } private static DateTime ArrivalEnd; public static DateTime arrivalEnd { get { return ArrivalEnd; } set { ArrivalEnd = value; } } private static DateTime DepartureStart; public static DateTime departureStart { get { return DepartureStart; } set { DepartureStart = value; } } private static DateTime DepartureEnd; public static DateTime departureEnd { get { return DepartureEnd; } set { DepartureEnd = value; } } public Tabs() { InitializeComponent(); LoadSubsidiaryXML(); dtpArrivalStart.Format = DateTimePickerFormat.Custom; dtpArrivalStart.CustomFormat = "ddd dd MMM yyyy hh:mm"; dtpArrivalEnd.Format = DateTimePickerFormat.Custom; dtpArrivalEnd.CustomFormat = "ddd dd MMM yyyy hh:mm"; dtpDepartureStart.Format = DateTimePickerFormat.Custom; dtpDepartureStart.CustomFormat = "ddd dd MMM yyyy hh:mm"; dtpDepartureEnd.Format = DateTimePickerFormat.Custom; dtpDepartureEnd.CustomFormat = "ddd dd MMM yyyy hh:mm"; } private void LoadSubsidiaryXML() { XmlDocument subsidiary = new XmlDocument(); subsidiary.Load("Subsidiaries.xml"); XmlNodeList Subname = subsidiary.SelectNodes("subsidiaries/type/name"); foreach (XmlNode name in Subname) { comboSubsidiaryTravel.Items.Add(name.InnerText); } } private void LoadWorkerXML(string xmlType) { comboWorkerType.Items.Clear(); XmlDocument workerType = new XmlDocument(); workerType.Load(xmlType); XmlNodeList worker = workerType.SelectNodes("worker/type/name"); foreach (XmlNode name in worker) { comboWorkerType.Items.Add(name.InnerText); } } //Select XML which have to be populated to comboWorkerType private void chooseWorker() { string xmlType = ""; string subsidiary = ""; subsidiary = comboSubsidiaryTravel.Text; switch (subsidiary) { case "GH": xmlType = "GHworkerType.xml"; LoadWorkerXML(xmlType); break; case "GP": xmlType = "GPworkerType.xml"; LoadWorkerXML(xmlType); break; case "GN": xmlType = "GNworkerType.xml"; LoadWorkerXML(xmlType); break; case "GT": xmlType = "GTworkerType.xml"; LoadWorkerXML(xmlType); break; case "GS": xmlType = "GSworkerType.xml"; LoadWorkerXML(xmlType); break; case "GK": xmlType = "GKworkerType.xml"; LoadWorkerXML(xmlType); break; case "GBH": xmlType = "GBHworkerType.xml"; LoadWorkerXML(xmlType); break; case "GAS": xmlType = "GASworkerType.xml"; LoadWorkerXML(xmlType); break; case "Others": comboWorkerType.Items.Clear(); break; default: break; } } private void comboSubsidiaryTravel_SelectedIndexChanged(object sender, EventArgs e) { chooseWorker(); } private void dtpArrivalStart_ValueChanged(object sender, EventArgs e) { ArrivalStart = dtpArrivalStart.Value; dtpArrivalEnd.MinDate = dtpArrivalStart.Value; } private void dtpArrivalEnd_ValueChanged(object sender, EventArgs e) { ArrivalEnd = dtpArrivalEnd.Value; dtpDepartureStart.MinDate = dtpArrivalEnd.Value; } private void dtpDepartureStart_ValueChanged(object sender, EventArgs e) { DepartureStart = dtpDepartureStart.Value; dtpDepartureEnd.MinDate = dtpDepartureStart.Value; } private void dtpDepartureEnd_ValueChanged(object sender, EventArgs e) { DepartureEnd = dtpDepartureEnd.Value; } } } </code></pre> <p>and I'm adding a new tab with a button:</p> <pre><code>private void btnAddWorker_Click(object sender, EventArgs e) { string title = "worker " + (tabsTravel.TabCount + 1).ToString(); TabPage test = new TabPage(); tabsTravel.TabPages.Add(test); test.Text = title; test.BackColor = Color.White; test.Controls.Add(new Tabs()); } </code></pre> <p>Adding the tabs with the button and removing them with another button works fine, but now I got some Problems:</p> <ol> <li>the comboWorkerType is depending on what is selected in the comboSubsidiaryTravel. but in all dynamically added tabs, the XML isn't loaded to the comboWorkerType if I selected an item in comboSubsidiaryTravel. </li> <li>how can I access the dynamically added controls and their values like datetimepicker?</li> </ol> <p>greetz</p> <p>Tobi</p> <p>EDIT:</p> <p>this is the class where I'm using the values of the Datetimepicker:</p> <pre><code>namespace Demo { class worker { public void ArrivalTimeSpan() { TimeSpan Arrival = new TimeSpan(); Arrival = Page2.arrivalEnd - Page2.arrivalStart; System.Windows.Forms.MessageBox.Show(Arrival.ToString()); } public void DepartureTimeSpan() { TimeSpan Departure = new TimeSpan(); Departure = Page2.departureEnd - Page2.departureStart; System.Windows.Forms.MessageBox.Show(Departure.ToString()); } public void WorkTimeSpan() { TimeSpan Work = new TimeSpan(); Work = Page3.workEnd - Page3.workStart; System.Windows.Forms.MessageBox.Show(Work.ToString()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload