I am attempting to arrange a listbox according to company name....I have the listbox loaded with peoples names and the company they work for like so
example
Joe - UPS
Tim - UPS
Sara - FPL
Scott - Coastal
Alex - UPS
Luis - FPL
there will be an unknown number of names in the listbox......what I need to do is arrange the listbox so that all the company names are itogether and the names that have only one company, they need to be at the end....the code I wrote kind of works...but not quite....please take a look at it and help me figure out how to do this.
Thank You for any help
-InkedGFX
example
Joe - UPS
Tim - UPS
Sara - FPL
Scott - Coastal
Alex - UPS
Luis - FPL
there will be an unknown number of names in the listbox......what I need to do is arrange the listbox so that all the company names are itogether and the names that have only one company, they need to be at the end....the code I wrote kind of works...but not quite....please take a look at it and help me figure out how to do this.
private List<string> Arrange_List() { if (lstPlayers.Items.Count < 1) { return matchedCompany_List; } else { for (int i = 0; i < lstPlayers.Items.Count; i++) { for (int y = i + 1; y <= i + 1; y++) { if (i == lstPlayers.Items.Count - 1) { } else { string[] first_values = lstPlayers.Items[i].ToString().Split('-'); string first_company = first_values[1]; string[] second_values = lstPlayers.Items[y].ToString().Split('-'); string second_company = second_values[1]; if (second_company == first_company) { matchedCompany_List.Add(lstPlayers.Items[i].ToString()); matchedCompany_List.Add(lstPlayers.Items[y].ToString()); } else { unmatchedCompany_List.Add(lstPlayers.Items[y].ToString()); } } } } } return matchedCompany_List; }
Thank You for any help
-InkedGFX