Reputation: 11
I currently have this code, what it does is from another form i select genres and the selected genres will be placed in a textbox when ok is pressed this is the code for the OK button:
But i have an issue When i am in the genre's form and i select 3 at the same time for example Action & Adventure, Comedy, Drama it writes them well in the text box but when i open the form again and select another genre and press ok, then it will show like this: Action & Adventure,, Comedy and if i select another it will add 2 commas after comedy
private void OkayButton_Click(object sender, EventArgs e)
{
string Temp = "";
foreach (string Genre in SelectedGenresList)
{
Temp += Genre + ", ";
}
SelectedGenres = Temp;
this.DialogResult = DialogResult.OK;
this.Close();
}
Upvotes: 0
Views: 258
Reputation: 31
add the selected genre to a list. than you can easily "merge" the entries to a string with delimiter. example:
List<string> names = new List<string>() { "John", "Anna", "Monica" };
var result = String.Join(", ", names.ToArray());
Upvotes: 1