Click here to Skip to main content
14,880,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wrote above method to import unread mail details to data gride from outlook 2007. it is working perfectlly but because mail.BodyContent = MessageBox.Show(mailItem.Body); that code it give mail body without stopping what i need to do is i need to open perticuler body when i click relavent button in the data gride .. pls tell me how can i do it i am haveing buttons as mail body column thank you

C#
private List<unreademails> GetEmailsFromFolder(string folderName)
    {
        List<unreademails> emails = null;

        object missing = System.Reflection.Missing.Value;

        try
        {
            Outlook.MAPIFolder fldEmails = null;
            emails = new List<unreademails>();
            Outlook._Application outlookObj = new Outlook.Application();
            if (folderName == "Default")
            {
                fldEmails = (Outlook.MAPIFolder)outlookObj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            }

            else
            {
                Outlook.MAPIFolder emailFolder = (Outlook.MAPIFolder)
                    outlookObj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

                foreach (Outlook.MAPIFolder subFolder in emailFolder.Folders)
                {
                    if (subFolder.Name == folderName)
                    {
                        fldEmails = subFolder;
                        break;

                    }
                }
            }

            foreach (Microsoft.Office.Interop.Outlook._MailItem mailItem in fldEmails.Items)
            {
                if (mailItem.UnRead)
                {
                    UnreadEmails mail = new UnreadEmails();
                    {
                        mail.SenderName = (mailItem.UnRead == false) ? string.Empty : mailItem.SenderName;
                        mail.SenderAddress = (mailItem.UnRead == false) ? string.Empty : mailItem.SenderEmailAddress;
                        mail.Subject = (mailItem.UnRead == false) ? string.Empty : mailItem.Subject;


                            mail.BodyContent = MessageBox.Show(mailItem.Body);



                        mail.Attachment = "View Attachments";
                        emails.Add(mail);
                    }
                }
            } </unreademails></unreademails></unreademails>


[Modified: generally, it's better to place your question first, then your code. People see lots of code and sometimes don't bother if there's not a question. Also, "code block" (pre tags) are to be used for large blocks of code like you did. However, "inline code" (code tags) are not meant to be used inside of the pre tags. They're meant if you want to highlight a method within a sentence, like RunHelloWorld]
Posted
Updated 28-Jun-10 8:43am
v2

1 solution

First, do you understand what MessageBox.Show() returns? Because you're setting mail.BodyContent equal to a string representation of a DialogResult (assuming that mail.BodyContent is a string value).

Secondly, if what you want is to display the body of a message using a MessageBox when the message is clicked in the DataGridView, then you need to hook the CellClick or CellMouseClick event and then display the information in the cell with the given ColumnIndex and RowIndex.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900