Hi,
In my win forms app i have a listbox and a textbox the app gets email from a server and displays the subject etc in the listbox and when i click the listbox the body is shown in the textbox. The problem is i have to repeat the enitre code below in the selected index changed event to get it to work otherwise i get "does not exists in current context" error this slows down the app.
// Create an object, connect to the IMAP server, login,
// and select a mailbox.
Chilkat.Imap imap = new Chilkat.Imap();
imap.UnlockComponent("");
imap.Port = 993;
imap.Ssl = true;
imap.Connect("imap.gmail.com");
imap.Login("[email protected]", "pass");
imap.SelectMailbox("Inbox");
// Get a message set containing all the message IDs
// in the selected mailbox.
Chilkat.MessageSet msgSet;
msgSet = imap.Search("ALL", true);
// Fetch all the mail into a bundle object.
Chilkat.EmailBundle bundle = new Chilkat.EmailBundle();
bundle = imap.FetchBundle(msgSet);
// Loop over the bundle and display the From and Subject.
Chilkat.Email email;
int i;
for (i = 0; i < bundle.MessageCount - 1; i++)
{
email = bundle.GetEmail(i);
listView1.Items.Add(email.From + ": " + email.Subject).Tag = i;
richTextBox1.Text = email.Body;
}
// Save the email to an XML file
bundle.SaveXml("bundle.xml");
and here is the code i would like to get to work in the selected index changed event
if (listView1.SelectedItems.Count > 0)
{
richTextBox1.Text = bundle.GetEmail((int)listView1.SelectedItems[0].Tag).Body;
}
Thanks