I wrote an XML reader that converts the XML to a flat file or removes select elements from the XML file and saves the file.
The following controls are involved:
listbox1 – Containing a list of customers
comboBox1 – Which contains a drop down for a selection of “.log”, “.txt”, “.XML”
txtDateFormat – Containing the date format varying by customer
Using the Settings.Default…I’ve tested the settings for only have one customer in the listbox and that worked fine for saving the settings and reloading them when the form opens.
Now for the challenge, I’ve added the ability to add additional customers to the listbox1 and save those to an array. Let’s say each customer in the listbox needs different settings saved. For example,
{ Customer1: “.log”, “MM_dd_yyyy” }*
{ Customer2: “.txt”, “yyyy_MM_dd” }
{ Customer3: “.log”, No date format }
I’m assuming this would be controlled from listbox1_SelectedIndexChanged but how would I associate each customer to it’s own independent settings for each individual customer? Meaning, as I add additional customers and store the property settings, Customer1 would have different property settings then Customer2 would have different property settings and so on. So basically, when you click on each customer, you will see the settings change as well such as the dateformat, combobox, parameters, etc. I've included the screenshots of the "Options" window to hopefully make better sense.
private void lstBoxCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox.SelectedObjectCollection selectedItems = new ListBox.SelectedObjectCollection(lstBoxCustomer);
selectedItems = lstBoxCustomer.SelectedItems;
if (lstBoxCustomer.SelectedIndex != -1)
{
for (int i = selectedItems.Count - 1; i >= 0; i--)
lstBoxCustomer.Items.ToString();
txtCustomerName.Text = lstBoxCustomer.SelectedItem.ToString();
string FullCustomerName = lstBoxCustomer.SelectedItem.ToString();
string SplitCustName = FullCustomerName.Split('(')[0];
string SNTCodeSplit = FullCustomerName.Split('(', ')')[1];
txtCustomerName.Text = SplitCustName;
txtSNTCode.Text = SNTCodeSplit;
}
for (int i = 0; i < lstBoxCustomer.Items.Count; i++)
{
if (lstBoxCustomer.SelectedIndex == i)
{
if (Settings.Default.Setting_Default_File_Extension[i].ToString().Contains("log"))
{
cmbFileExtension.SelectedIndex = 0; //Log
}
else if (Settings.Default.Setting_Default_File_Extension[i].ToString().Contains("txt"))
{
cmbFileExtension.SelectedIndex = 1; //Txt
}
txtDateFormat.Text = Settings.Default.Setting_Date_Format[i].ToString();
}
}
}