VB.net outlook表单区域listview数据到userproperties

时间:2015-01-24 11:51:08

标签: vb.net listview outlook

我对vb.net的编程前景感到陌生,因此为什么我会在这里。 我已经为包含listview的Task对象创建了一个包含表单区域的outlook外接程序 该值列表包含4列,用户可以向其中添加一些文本。 添加到列表视图中的每个项目都将在退出时填充Outlook用户属性,我目前按照子项目(列)将其编程为其自己的用户属性,使用项目索引作为标识符(不确定这是否是最好的方法但是到目前为止工作) 我现在需要做的是在重新打开对象时使用任务用户属性值填充listview。

我找到最后一个listview项目索引号,然后使用这个数字作为范围来查找其他属性,不确定这是否是最好的方法或如何实现它但是任何帮助非常欢迎。

我的表单区域代码位于

之下

提前致谢

Public Class FormRegion1

Dim obTask As Outlook.TaskItem
Dim obDisID As Outlook.UserProperty
Dim obDisCustCom As Outlook.UserProperty
Dim obDisDHCom As Outlook.UserProperty
Dim obDisUser As Outlook.UserProperty
Dim obDisTime As Outlook.UserProperty

地区"表格地区工厂"

<Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Task)> _
<Microsoft.Office.Tools.Outlook.FormRegionName("test3.FormRegion1")> _
Partial Public Class FormRegion1Factory

    ' Occurs before the form region is initialized.
    ' To prevent the form region from appearing, set e.Cancel to true.
    ' Use e.OutlookItem to get a reference to the current Outlook item.
    Private Sub FormRegion1Factory_FormRegionInitializing(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs) Handles Me.FormRegionInitializing

    End Sub

End Class

结束地区

'Occurs before the form region is displayed. 
'Use Me.OutlookItem to get a reference to the current Outlook item.
'Use Me.OutlookFormRegion to get a reference to the form region.
Private Sub FormRegion1_FormRegionShowing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing
    obTask = Me.OutlookItem

End Sub

'Occurs when the form region is closed.   
'Use Me.OutlookItem to get a reference to the current Outlook item.
'Use Me.OutlookFormRegion to get a reference to the form region.
Private Sub FormRegion1_FormRegionClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionClosed

    For Each itm As ListViewItem In ListView1.Items
        obDisID = obTask.UserProperties.Add("obDisID" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisID.Value = itm.Index
        obDisCustCom = obTask.UserProperties.Add("obDisCustCom" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisCustCom.Value = itm.SubItems.Item(1).Text
        obDisDHCom = obTask.UserProperties.Add("obDisDHCom" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisDHCom.Value = itm.SubItems.Item(2).Text
        obDisUser = obTask.UserProperties.Add("obDisUser" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisUser.Value = itm.SubItems.Item(3).Text
        obDisTime = obTask.UserProperties.Add("obDisTime" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisTime.Value = itm.SubItems.Item(4).Text
    Next

    obTask.Save()

End Sub

1 个答案:

答案 0 :(得分:0)

导入System.Windows.Forms

Public Class FormRegion1

Dim obTask As Outlook.TaskItem
Dim obDisID As Outlook.UserProperty
Dim obDisTotal As Outlook.UserProperty

Dim obDisCustCom As Outlook.UserProperty
Dim obDisDHCom As Outlook.UserProperty
Dim obDisUser As Outlook.UserProperty
Dim obDisTime As Outlook.UserProperty

地区&#34;表格地区工厂&#34;

<Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Task)> _
<Microsoft.Office.Tools.Outlook.FormRegionName("test3.FormRegion1")> _
Partial Public Class FormRegion1Factory

    ' Occurs before the form region is initialized.
    ' To prevent the form region from appearing, set e.Cancel to true.
    ' Use e.OutlookItem to get a reference to the current Outlook item.
    Private Sub FormRegion1Factory_FormRegionInitializing(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs) Handles Me.FormRegionInitializing

    End Sub

End Class

结束地区

'Occurs before the form region is displayed. 
'Use Me.OutlookItem to get a reference to the current Outlook item.
'Use Me.OutlookFormRegion to get a reference to the form region.
Private Sub FormRegion1_FormRegionShowing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing
    obTask = Me.OutlookItem

    obDisTotal = obTask.UserProperties.Find("obDisTotal")
    If obDisTotal Is Nothing Then

    Else

        For i = 0 To obDisTotal.Value
            obDisID = obTask.UserProperties.Find("obDisID" & i)
            obDisCustCom = obTask.UserProperties.Find("obDisCustCom" & i)
            obDisDHCom = obTask.UserProperties.Find("obDisDHCom" & i)
            obDisUser = obTask.UserProperties.Find("obDisUser" & i)
            obDisTime = obTask.UserProperties.Find("obDisTime" & i)

            Dim Str(5) As String
            Dim Itm As ListViewItem
            Str(0) = obDisID.Value
            Str(1) = obDisCustCom.Value
            Str(2) = obDisDHCom.Value
            'Str(3) = NS.CurrentUser.ToString
            Str(4) = obDisTime.Value

            Itm = New ListViewItem(Str)
            ListView1.Items.Add(Itm)
        Next

    End If

End Sub


'Occurs when the form region is closed.   
'Use Me.OutlookItem to get a reference to the current Outlook item.
'Use Me.OutlookFormRegion to get a reference to the form region.
Private Sub FormRegion1_FormRegionClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionClosed

    For Each itm As ListViewItem In ListView1.Items
        obDisID = obTask.UserProperties.Add("obDisID" & itm.Index, Outlook.OlUserPropertyType.olInteger, True, True)
        obDisID.Value = itm.Index
        obDisCustCom = obTask.UserProperties.Add("obDisCustCom" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisCustCom.Value = itm.SubItems.Item(1).Text
        obDisDHCom = obTask.UserProperties.Add("obDisDHCom" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisDHCom.Value = itm.SubItems.Item(2).Text
        obDisUser = obTask.UserProperties.Add("obDisUser" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisUser.Value = itm.SubItems.Item(3).Text
        obDisTime = obTask.UserProperties.Add("obDisTime" & itm.Index, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
        obDisTime.Value = itm.SubItems.Item(4).Text
        obDisTotal = obTask.UserProperties.Add("obDisTotal", Outlook.OlUserPropertyType.olInteger, True, True)
        obDisTotal.Value = itm.Index
    Next

    obTask.Save()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim form1 As New Form1()
    form1.ShowDialog()
End Sub

结束班