2
Reply

Give a file name based on selected Items from ComboBoxes

Rano AH

Rano AH

11 years ago
1.1k

Hi Vulpes

Not sure if you received this, since I posted similar to one of the already answered questions by your self. This is why I'm posting it here as a new question, hope to hear from you soon or from other guys who are available


 private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
 {
 string[] exclusions = { selectedItem };
 Fill(comboBox2, exclusions);
 Fill(comboBox3, exclusions);
 Fill(comboBox4, exclusions);
 mySelectedItems = exclusions;
 }
 

 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
 {
 string selectedItem1 = comboBox1.SelectedItem.ToString();
 string selectedItem2 = comboBox2.SelectedItem.ToString();
 string[] exclusions = { selectedItem1, selectedItem2 };
 Fill(comboBox3, exclusions);
 Fill(comboBox4, exclusions);
 mySelectedItems = exclusions;
 }
 

 private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
 {
 if (comboBox1.SelectedIndex == -1 || comboBox2.SelectedIndex == -1) comboBox3.SelectedIndex = -1;
 if (comboBox3.SelectedIndex == -1) return;
 string selectedItem1 = comboBox1.SelectedItem.ToString();
 string selectedItem2 = comboBox2.SelectedItem.ToString();
 string selectedItem3 = comboBox3.SelectedItem.ToString();
 string[] exclusions = { selectedItem1, selectedItem2, selectedItem3 };
 Fill(comboBox4, exclusions);
 comboBox4.SelectedIndex = 0;
 mySelectedItems = exclusions;
 }
 
 private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
 {
 if (comboBox1.SelectedIndex == -1 || comboBox2.SelectedIndex == -1 || comboBox3.SelectedIndex == -1)
 comboBox4.SelectedIndex = -1;
 string selectedItem1 = comboBox1.SelectedItem.ToString();
 string selectedItem2 = comboBox2.SelectedItem.ToString();
 string selectedItem3 = comboBox3.SelectedItem.ToString();
 string selectedItem4 = comboBox4.SelectedItem.ToString();
 string[] exclusions = { selectedItem1, selectedItem2, selectedItem3,selectedItem4 };
 mySelectedItems = exclusions;
 }
 

 In myFunction which reads the lines from a text file:
 
 var list = new List();
 
 using (var reader = new StreamReader(file))
 {
 for (int i = 1; i <= 10; i++)
 {
 list.Add(reader.ReadLine());
 }
 }
 
 string[] MatchesValues = new string[4];
 
 if((mySelectedItems[0]=="Oman" ) || (mySelectedItems[1]=="Oman" ) || (mySelectedItems[2]=="Oman") || (mySelectedItems[3]=="Oman"))
 {
 MatchesValues[0] = list[2]; // this will set the value of list[2] to store it int matchesValues[0]
 }
 if ((mySelectedItems[0] == "USA") || (mySelectedItems[1] == "USA") || (mySelectedItems[2] == "USA") || (mySelectedItems[3] == "USA"))
 {
 MatchesValues[1] = list[5];// this will set the value of list[5] to store it int matchesValues[1]
 }
 if ((mySelectedItems[0] == "Saudi Arabia") || (mySelectedItems[1] == "Saudi Arabia") || (mySelectedItems[2] == "Saudi Arabia") ||
 
 (mySelectedItems[3] == "Saudi Arabia"))
 {
 MatchesValues[2] = list[8];// this will set the value of list[8] to store it int matchesValues[2]
 }
 if ((mySelectedItems[0] == "UAE") || (mySelectedItems[1] == "UAE") || (mySelectedItems[2] == "UAE") || (mySelectedItems[3] == "UAE"))
 {
 MatchesValues[3] = list[9];// this will set the value of list[9] to store it int matchesValues[3]
 }
 
 But I stop here. When I click the "Process" button, a file name must show the correspondence values based on the order of my selected items.
 Example: if I selected USA from ComboBox1, and then UAE from ComboBox2 and then Saudi Arabia from comboBox3 then the textbox must show only the value of list[5], list [9] and then list [8] (respectively)


Answers (2)