string []和字符串到DataGridView-Datasource

时间:2013-11-07 13:48:02

标签: c# datagrid datagridview datasource

我收集了类" Microsoft.Exchange.Management.TransportLogSearchTasks.MessageTrackingEvent" 这是微软课程。

此类构建类似于以下类

public class  MTE 
    {
        private DateTime timestamp;
        private string clientIp;
        private string clientHostname;
        private string serverIp;
        private string serverHostname;
        private string sourceContext;
        private string connectorId;
        private string source;
        private string eventId;
        private string internalMessageId;
        private string messageId;
        private string[] recipients;
        private string[] recipientStatus;
        private int? totalBytes;
        private int recipientCount;
        private string relatedRecipientAddress;
        private string[] reference;
        private string messageSubject;
        private string sender;
        private string returnPath;
        private string messageInfo;

        private new DateTime Timestamp
        {
            get { return timestamp; }
            set { timestamp = value; }
        }

        public new string ClientIp
        {
            get { return clientIp; }
            set { clientIp = value; }
        }

        public new string ClientHostname
        {
            get { return clientHostname; }
            set { clientHostname = value; }
        }

        public new string ServerIp
        {
            get { return serverIp; }
            set { serverIp = value; }
        }
        public new string ServerHostname
        {
            get { return serverHostname; }
            set { serverHostname = value; }
        }
        public new string SourceContext
        {
            get { return sourceContext; }
            set { sourceContext = value; }
        }
        public new string ConnectorId
        {
            get { return connectorId; }
            set { connectorId = value; }
        }
        public new string Source
        {
            get { return source; }
            set { source = value; }
        }
        public new string EventId
        {
            get { return eventId; }
            set { eventId = value; }
        }
        public new string InternalMessageId
        {
            get { return internalMessageId; }
            set { internalMessageId = value; }
        }
        public new string MessageId
        {
            get { return messageId; }
            set { messageId = value; }
        }
        public new string[] Recipients
        {
            get { return recipients; }
            set { recipients = value; }
        }
        public new string RecipientStatus
        {
            get { return[] recipientStatus; }
            set { recipientStatus = value; }
        }
        public new int? TotalBytes
        {
            get { return totalBytes; }
            set { totalBytes = value; }
        }
        public new int RecipientCount
        {
            get { return recipientCount; }
            set { recipientCount = value; }
        }
        public new string RelatedRecipientAddress
        {
            get { return relatedRecipientAddress; }
            set { relatedRecipientAddress = value; }
        }
        public new string Reference
        {
            get { return[] reference; }
            set { reference = value; }
        }
        public new string MessageSubject
        {
            get { return messageSubject; }
            set { messageSubject = value; }
        }
        public new string Sender
        {
            get { return sender; }
            set { sender = value; }
        }
        public new string ReturnPath
        {
            get { return returnPath; }
            set { returnPath = value; }
        }
        public new string MessageInfo
        {
            get { return messageInfo; }
            set { messageInfo = value; }
        }

}

当我在做什么时

Collection<MTE> newMTE = new Collection<MTE>();
datagridview1.datasource= newMTE;
datagrid1.datasource = newMTE
在DGV上的

我可以看到所有string []属性 在datagrid上我可以看到它们但是作为属性类型而不是值 图片示例:

http://farm6.staticflickr.com/5519/10725217114_226ddd96c7_m.jpg

我的收藏有数百万行,所以我需要一个易于处理的解决方案。

谢谢大家的帮助

1 个答案:

答案 0 :(得分:0)

newMTE本身就是一个集合,你的string[]也是项目集合(字符串数组)。 您可以使用分组或显示行详细信息来显示行的子行。

这里的例子: http://www.wpftutorial.net/DataGrid.html