private void Tab_Selected(object sender, TabPage tab) { FieldInfo[] fields = GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo field in fields) { var obj = field.GetValue(this); // release memory for the current tab if (obj is DataViewer view) { view.GridView.Rows.Clear(); GC.Collect(); GC.WaitForPendingFinalizers(); } } switch (TabControlMain.SelectedTab.Controls[0]) { case DataViewer view: { // no child control GridIOUtility.ImportGrid($"{TabControlMain.SelectedTab.Text}/{tab.Text}.bin", view.GridView, AddGridRow); break; } case TabControl childTab: { DataViewer view = (DataViewer)childTab.SelectedTab.Controls[0]; GridIOUtility.ImportGrid($"{TabControlMain.SelectedTab.Text}/{tab.Text}.bin", view.GridView, AddGridRow); break; } } }
/// <summary> /// upon clicking the save button, store data of the current opened grid. /// Some tabs may have another TabControl in which that Control contains a Grid control. /// </summary> private void BtnSave_Click(object sender, EventArgs ev) { MouseEventArgs e = (MouseEventArgs)ev; switch (e.Button) { case MouseButtons.Left: { switch (TabControlMain.SelectedTab.Controls[0]) { case DataViewer view: // no child tabs and contains 1 child Control (DataGridView) GridIOUtility.ExportGrid(view, TabControlMain.SelectedTab.Text); break; case TabControl tab: // contains child controls (e.g. Equips.Hairs, Equips.Faces) GridIOUtility.ExportGrid((DataViewer)tab.SelectedTab.Controls[0], TabControlMain.SelectedTab.Text); // The DataGridView contained in the TabPage control break; } MessageBox.Show(Resources.CompleteSaveBIN); break; } case MouseButtons.Right: { var control = TabControlMain.SelectedTab.Controls[0]; if (control is DataViewer dataViewer) // no child tabs and contains 1 child Control (DataGridView) { GridIOUtility.ExportGridImages(dataViewer.GridView, TabControlMain.SelectedTab.Text); } else if (control is TabControl tab) // contains child controls (e.g. Equips.Hairs, Equips.Faces) { control = tab.SelectedTab; // The selected child Tab (e.g. Equips.Hairs) GridIOUtility.ExportGridImages((DataGridView)control.Controls[0], TabControlMain.SelectedTab.Text); // The DataGridView contained in the TabPage control } MessageBox.Show(Resources.CompleteSaveImages); break; } } }
private void MainForm_Load(object sender, EventArgs e) { GridIOUtility.ImportGrid("equips/Hairs.bin", EquipHairsView.GridView, AddGridRow); }