There are 3 related forms:
User Selects from the lists from "subCategoriesform" based on the selected category, and at the end all of his selected items from different sub categories should be shown in the main listbox (located listbox at the mainform) and also all related prices should be SUM and show as "Total Price".
I was thinking to do it with Hashtable, what do you think? is there any clean solution for this?
The first thing that comes to mind is make some public list in each form and get them in main form
//some where in Main Form
Form2 _frm=new Form2();
listofall.Concat(_frm.listofform2); //listofall is list of Main Form
//Make same to all other forms
Give your forms business properties that the previous form can use to get the selection. In example below, it just allows a single item selection. But you can adapt it to allow user to select a list of items before closing the form.
public class BaseSelectionForm : Form
{
public string Selection { get; protected set; }
}
public class MainForm : Form
{
public List<string> Selections { get; set; }
private void ButtonClick(object sender, EventArgs e)
{
using (var dialog = new CategoryForm())
{
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Selections.Add(dialog.Item);
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
else
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
}
}
}
public class CategoryForm : BaseSelectionForm
{
private void ButtonClick(object sender, EventArgs e)
{
using (var dialog = new SubCategoryForm())
{
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Selection = "This Category Name > " + dialog.Item;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
else
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
}
}
}
public class SubCategoryForm : BaseSelectionForm
{
private void ButtonClick(object sender, EventArgs e)
{
Selection = "Brown Shirt / $34.00";
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.