I need some help i can't figure out whats wrong with my code, everytime i try to get the program to display the SelectedItems i get "system.windows.forms.listbox+selectedobjectcollection". I can get text from the combobox to the emailBankListBox1 but when i try to hop from the emailBanklistBox1 to listBox1 i get the text listed above. Any and all help is much appreciated.
private void addButton1_Click(object sender, EventArgs e)
{
/*
int selectIndexInt = -1;
selectIndexInt = recipientComboBox.SelectedIndex;
if (selectIndexInt != -1)
{
emailBankListBox1.Items.Add(recipientComboBox.SelectedItem += ",");
}
else
{
}
*/
if (recipientComboBox.Text == "")
{
MessageBox.Show("Please enter a Recipient Email");
}
else
{
emailBankListBox1.Items.Add(recipientComboBox.Text += ",");
}
for (int i = 0; i < emailBankListBox1.Items.Count; i++)
{
emailBankListBox1.SetSelected(i, true);
}
}
private void removeButton2_Click(object sender, EventArgs e)
{
int selectIndexInt = -1;
selectIndexInt = emailBankListBox1.SelectedIndex;
if (selectIndexInt != -1)
{
emailBankListBox1.Items.RemoveAt(selectIndexInt);
}
else
{
MessageBox.Show("Select a name from the 'Recipients to recieve email' List");
}
}
private void button5_Click(object sender, EventArgs e)
{
this.Close();
}
private void button4_Click(object sender, EventArgs e)
{
/*
for (int i = 0; i < emailBankListBox1.Items.Count; i++)
{
emailBankListBox1.SetSelected(i, true);
}
*/
var selectedString = emailBankListBox1.SelectedItems.ToString();
listBox1.Items.Add(selectedString);
/*
//Email sending
MailMessage myMail = new MailMessage();
myMail.To.Add(new MailAddress(emailBankListBox1.SelectedItems.ToString()));
myMail.From = new MailAddress("******m", "******");
myMail.Subject = subjectTextBox.Text;
myMail.Body = bodyTextBox.Text;
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("*********", "*****");
try
{
smtp.Send(myMail);
MessageBox.Show("Message Sent");
}
catch
{
MessageBox.Show("Cannot send this message");
}
*/
}
private void recipientComboBox_SelectedValueChanged(object sender, EventArgs e)
{
int selectIndexInt = -1;
selectIndexInt = recipientComboBox.SelectedIndex;
if (selectIndexInt != -1)
{
emailBankListBox1.Items.Add(recipientComboBox.SelectedItem += ",");
}
else
{
if (recipientComboBox.Text == "")
{
MessageBox.Show("Please type or select a recipient E-mail");
}
}
for (int i = 0; i < emailBankListBox1.Items.Count; i++)
{
emailBankListBox1.SetSelected(i, true);
}
}