我正在尝试使用以下代码将DASL查询结果(Outlook表)填充到VB.NET表单中的DataGridView中。尽管Outlook表具有结果,但数据不会以该格式填充-也不会出现错误。请帮忙。
Dim oT As Outlook.Table = eFolder.GetTable(strFilter)
oT.Sort("[SentOn]", True)
Me.DataGridView1.DataSource = oT
答案 0 :(得分:1)
DataGridView.DataSource不了解Outlook.Table
COM对象。将其转换为控件可以理解的内容是您的责任。
答案 1 :(得分:1)
Outlook的表和DataSource
实例是完全不同的实体。您需要自己在代码中创建绑定对象,以从Items
集合中提取必填字段。
DataGridView
类支持标准Windows窗体数据绑定模型。这意味着数据源可以是实现以下接口之一的任何类型:
IList
接口,包括一维数组。IListSource
接口,例如DataTable和DataSet类。IBindingList
接口,例如BindingList类。IBindingListView
接口,例如BindingSource类。如您所见,Outlook没有为此提供任何功能。
答案 2 :(得分:0)
对于任何寻求答案的人,下面是代码
Dim RowCount As Integer = oT.GetRowCount
Dim DtaSet(RowCount, 6) As String
Dim VarArray As Array
VarArray = oT.GetArray(RowCount)
Dim myarr(RowCount) As mystructure
For ix As Integer = 0 To RowCount - 1
myarr(ix) = New mystructure With
{
.From = VarArray(ix, 0).ToString,
.EmailTo = VarArray(ix, 1).ToString,
.CC = VarArray(ix, 2).ToString,
}
Next
DataGridView1.DataSource = myarr
继续如下:
Structure mystructure
Private mFrom As String
Private mEmailTo As String
Private mCC As String
Public Property From() As String
Get
Return mFrom
End Get
Set(ByVal value As String)
mFrom = value
End Set
End Property
Public Property EmailTo() As String
Get
Return mEmailTo
End Get
Set(ByVal value As String)
mEmailTo = value
End Set
End Property
Public Property CC() As String
Get
Return mCC
End Get
Set(ByVal value As String)
mCC = value
End Set
End Property