Hello everyone. I am a C# learner. I am having troubles doing my first program.
Part of the function is to sort a list box contain client details.
For instance:
One typical line of the contactListBox is:
Surname Firstname Firstmeetingdate Location Phone
I have work out the "sort by surname" button, it is simple to loop through the contactListBox using an array and sort and return, because the surname is the first string in every single line.
- private void sortBySButton_Click(object sender, EventArgs e)
-
{
-
contactListBox.Items.Clear();
-
StreamReader fileReader;
-
string[] myArray;
-
string line = "";
-
string bigString = "";
-
fileReader = new StreamReader("client contact details.txt");
-
while (fileReader.Peek() != -1)
-
{
-
line = fileReader.ReadLine();
-
bigString = bigString + line + "\n";
-
}
-
fileReader.Close();
-
bigString = bigString.Trim();
-
myArray = bigString.Split('\n');
-
Array.Sort(myArray);
-
foreach (string item in myArray)
-
{
-
contactListBox.Items.Add(item);
-
}
-
}
Now I am having troubles coding the "sort by location" button, because I don't know where to tell the compiler to recognize the location string.
This has already drived me crazy!!!
Can somebody help me a little? None of the resource I found is suitable for a beginner. Thanks in advance.
- private void sortByLButton_Click(object sender, EventArgs e)
-
{
-
-
}
P.S. location is retrieved from locationComboBox.