简体   繁体   English

vb.net加载项Outlook将新字段添加到tableview

[英]vb.net add-in outlook add new field to tableview

I have a problem to add some fields to a tableview in outlook. 我在Outlook中将一些字段添加到表视图时遇到问题。

I would like to customize the inbox folder view. 我想自定义收件箱文件夹视图。

I have add some fields such as Receive, CC, to programatically. 我以编程方式添加了一些字段,如Receive,CC。

This is my code: 这是我的代码:

tblView.ViewFields.Add("To")
tblView.ViewFields.Add("Cc")
tblView.ViewFields.Add("Received")
tblView.Save()
tblView.Apply()

But it does not work. 但这行不通。 I do not know how to fix it. 我不知道如何解决。

outlook will give error when the table view already contains the fields to be added. 当表视图已经包含要添加的字段时,Outlook将给出错误。 so in order to make it work, it's essential to check whether the field exists already: 因此,为了使其工作,必须检查该字段是否已经存在:

<System.Runtime.CompilerServices.Extension()>
Public Shared Function AddField(theView As Outlook.TableView, fieldName As String) As Outlook.ViewField
    Dim theField As Outlook.ViewField = Nothing
    Try
        theField = theView.ViewFields(fieldName)
    Catch ex As Exception
    End Try
    If theField Is Nothing Then
        theField = theView.ViewFields.Add(fieldName)
    End If
    Return theField
End Function

then the fields can be added: 然后可以添加字段:

tblView.AddViewField("To")
tblView.AddViewField("Cc")
tblView.AddViewField("Received")
tblView.Save()
tblView.Apply()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM