列表绑定到datagride [英] List bind to datagride

查看:74
本文介绍了列表绑定到datagride的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了上面的方法,将未读的邮件详细信息从Outlook 2007导入到数据网格中.它工作得很好,但是因为mail.BodyContent = MessageBox.Show(mailItem.Body);该代码可以在不停止我需要做的事情的情况下给邮件正文,是我单击数据网格中的relavent按钮时需要打开perticuler正文.请告诉我我该怎么做,我有按钮作为邮件正文列,谢谢您

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

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>



[修改:通常,最好先提出您的问题,然后再提出您的代码.人们会看到很多代码,并且即使没有问题,有时也不会打扰.同样,代码块"(预标记)将像您一样用于大型代码块.但是,内联代码"(代码标签)并不意味着在预标签内部使用.它们的意思是,如果您想突出显示句子中的方法,例如RunHelloWorld]



[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]

推荐答案

首先,您了解MessageBox.Show()返回的内容吗?因为您将mail.BodyContent设置为等于DialogResult的字符串表示形式(假设mail.BodyContent是字符串值).

其次,如果要在DataGridView中单击消息时使用MessageBox显示消息的正文,则需要挂接CellClickCellMouseClick事件,然后在其中显示信息.具有给定ColumnIndexRowIndex的单元格.
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.


这篇关于列表绑定到datagride的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆