简体   繁体   中英

vb.net add-in outlook add new field to tableview

I have a problem to add some fields to a tableview in outlook.

I would like to customize the inbox folder view.

I have add some fields such as Receive, CC, to programatically.

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. 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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