I have a ListBox that has X amount (Varies from 9 - 90) of items. I'm trying to populate (On a button click) a string array with the items that are selected in the ListBox. Here is what I have so far
private void generateTam_Click(object sender, EventArgs e)
{
String sCombinedTam = "";
String sTamResponseStart = "Dear $contacts.name.first,@\n@\nYour request has been received and completed.@\nThe following actions were taken:@\n";
String sTamResponseEnd = "Thank you for choosing %company%, and have a great day!!@\n@\n$incidents.assigned.acct_id@\n%company%";
sTamResponseStart = sTamResponseStart.Replace("@\n", System.Environment.NewLine); //Replaces token @\n with NewLine
//Gets Actions Selected, Sends to Array
String[] sActionItemsSelected = new String[actionsListBox.Items.Count];
for (int x = 0; x < actionsListBox.Items.Count; ++x)
{
if (actionsListBox.GetSelected(x) == true)
{
actionsListBox.Items.CopyTo(sActionItemsSelected, 0);
}
}
//Gets Profiles Selected, Sends to Array
String[] sProfileItemsSelected = new String[profilesListBox.Items.Count];
for (int x = 0; x < profilesListBox.Items.Count; ++x)
{
if (profilesListBox.GetSelected(x) == true)
{
profilesListBox.Items.CopyTo(sProfileItemsSelected, x);
}
else if (profilesListBox.GetSelected(x) == false)
{
sProfileItemsSelected[x] = "";
}
}
//Combines strings for end response
for (int i = 0; i < sActionItemsSelected.Length; ++i)
{
sCombinedTam = sCombinedTam + sActionItemsSelected[i] + "@\n";
}
sCombinedTam = sCombinedTam.Replace("@\n", System.Environment.NewLine);
sTamResponseEnd = sTamResponseEnd.Replace("@\n", System.Environment.NewLine);
sCombinedTam = sTamResponseStart + sCombinedTam + sTamResponseEnd;
notesTextBox.Text = sCombinedTam;
//Outputs ENTIRE index ListBoxes not just selected items.
}
The problem comes at the end, instead of setting notesTextBox.Text to the combination string with only the ListBox Selected Items it sets it to the combination string with EVERY ListBox option.
Any help would be greatly appreciated.
sCombinedTam?Dear $contacts.name.first,@\n@\nYour request has been received and completed.@\nThe following actions were taken:@\n [Insert Action Selected 1] [Insert Action Selected 2] ... [Insert Action Selected 90] Thank you for choosing %company%, and have a great day!!@\n@\n$incidents.assigned.acct_id@\n%company%Where @\n is replaced with a new line.