翻譯|使用教程|編輯:龔雪|2024-11-18 10:28:16.883|閱讀 123 次
概述:本文主要介紹如何使用DevExpress WinForms的Data Grid組件在代碼中創建和管理數據以及應用數據注釋屬性,歡迎下載最新版組件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在本教程中您將學習如何在代碼中為網格控件創建數據源,還將看到如何應用數據屬性使網格應用適當的編輯模式、單元格編輯器和輸入驗證規則。
P.S:DevExpress WinForms擁有180+組件和UI庫,能為Windows Forms平臺創建具有影響力的業務解決方案。DevExpress WinForms能完美構建流暢、美觀且易于使用的應用程序,無論是Office風格的界面,還是分析處理大批量的業務數據,它都能輕松勝任!
獲取DevExpress WinForms v24.1正式版下載
DevExpress技術交流群11:749942875 歡迎一起進群討論
在創建新解決方案時,首先使用DevExpress模板集合中的DevExpress Project Wizard(項目向導)創建一個項目。
啟動應用程序,看到網格顯示了樣本數據。
切換到代碼來定位此數據的來源,向導會自動生成代碼,包括表單構造函數中的InitGrid方法調用。該方法使用Person類的5個實例填充BindingList,然后將BindingList對象分配給網格控件的屬性。
C#
class Person { string firstName; string secondName; string comments; public Person(string firstName, string secondName) { this.firstName = firstName; this.secondName = secondName; comments = String.Empty; } public Person(string firstName, string secondName, string comments) : this(firstName, secondName) { this.comments = comments; } public string FirstName { get { return firstName; } set { firstName = value; } } public string SecondName { get { return secondName; } set { secondName = value; } } public string Comments { get { return comments; } set { comments = value; } } } public Form1() { // ... InitGrid(); } BindingList<Person> gridDataList = new BindingList<Person>(); void InitGrid() { gridDataList.Add(new Person("John", "Smith")); gridDataList.Add(new Person("Gabriel", "Smith")); gridDataList.Add(new Person("Ashley", "Smith", "some comment")); gridDataList.Add(new Person("Adrian", "Smith", "some comment")); gridDataList.Add(new Person("Gabriella", "Smith", "some comment")); gridControl.DataSource = gridDataList; }
VB.NET
Friend Class Person Private firstName_Renamed As String Private secondName_Renamed As String Private comments_Renamed As String Public Sub New(ByVal firstName As String, ByVal secondName As String) Me.firstName_Renamed = firstName Me.secondName_Renamed = secondName comments_Renamed = String.Empty End Sub Public Sub New(ByVal firstName As String, ByVal secondName As String, ByVal comments As String) Me.New(firstName, secondName) Me.comments_Renamed = comments End Sub Public Property FirstName() As String Get Return firstName_Renamed End Get Set(ByVal value As String) firstName_Renamed = value End Set End Property Public Property SecondName() As String Get Return secondName_Renamed End Get Set(ByVal value As String) secondName_Renamed = value End Set End Property Public Property Comments() As String Get Return comments_Renamed End Get Set(ByVal value As String) comments_Renamed = value End Set End Property End Class Public Sub New() ' ... InitGrid() End Sub Private gridDataList As New BindingList(Of Person)() Private Sub InitGrid() gridDataList.Add(New Person("John", "Smith")) gridDataList.Add(New Person("Gabriel", "Smith")) gridDataList.Add(New Person("Ashley", "Smith", "some comment")) gridDataList.Add(New Person("Adrian", "Smith", "some comment")) gridDataList.Add(New Person("Gabriella", "Smith", "some comment")) gridControl.DataSource = gridDataList End Sub
在最簡單的情況下,這就是如何在代碼中創建數據。定義一個表示記錄的對象,然后創建這樣一個對象的集合,并將該集合分配給網格的屬性。
現在來看幾個用代碼創建數據并將其綁定到網格的示例。
您可以定義作為數據記錄的自定義類,本教程中的示例代碼文件包含3個類的定義:CompanyPublicInfo、CompanyPrivateInfo和Product,每個類都包含自己的屬性,這些屬性將用作數據字段。
C#
// ... public class CompanyPublicInfo { public string CompanyName { get; set; } public string Country { get; set; } public string City { get; set; } public string Url { get; set; } public string Email { get; set; } public string Phone { get; set; } public string AdditionalInfo { get; set; } } // ...
VB.NET
Public Class CompanyPublicInfo Public Property CompanyName() As String Public Property Country() As String Public Property City() As String Public Property Url() As String Public Property Email() As String Public Property Phone() As String Public Property AdditionalInfo() As String End Class
這個文件后面定義的GridSampleDataList類提供了3個方法:GetCompanyPrivateInfo、GetCompanyPublicInfo和GetProductSample,這些方法中的每一個都返回一個由相應類的對象填充的BindingList:
C#
public class GridSampleDataList { static public List<CompanyPublicInfo> GetCompanyPublicInfo() { return new List<CompanyPublicInfo> { new CompanyPublicInfo() { AdditionalInfo = "Some Info", City = "Glendale", CompanyName = "Developer Express", Country = "USA", Email = "info@devexpress.com", Phone = "1234567890", Url = "www.devexpress.com", }, // ... }; } // ... }
VB.NET
Public Class GridSampleDataList Public Shared Function GetCompanyPublicInfo() As List(Of CompanyPublicInfo) Return New List(Of CompanyPublicInfo) From { New CompanyPublicInfo() With { .AdditionalInfo = "Some Info", .City = "Glendale", .CompanyName = "Developer Express", .Country = "USA", .Email = "info@devexpress.com", .Phone = "1234567890", .Url = "www.devexpress.com" } } End Function ' ... End Class
現在創建允許應用程序用戶在這三個數據源之間切換的UI,返回到主表單設計,您可以看到添加到Ribbon Control的編輯器,下拉列表將包含三個與前面定義的數據源類型相對應的項。
現在處理事件,根據當前選擇的下拉列表項將不同的BindingList對象分配給網格的 。
C#
private void barEditItem1_EditValueChanged(object sender, EventArgs e) { DevExpress.XtraBars.BarEditItem item = sender as DevExpress.XtraBars.BarEditItem; if(item == null) return; switch (item.EditValue as string) { case "Company public info": gridControl.DataSource = GridSampleDataList.GetCompanyPublicInfo(); break; case "Company private info": gridControl.DataSource = GridSampleDataList.GetCompanyPrivateInfo(); break; case "Product info": gridControl.DataSource = GridSampleDataList.GetProductSample(); break; } }
VB.NET
Private Sub barEditItem1_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs) Dim item As DevExpress.XtraBars.BarEditItem = TryCast(sender, DevExpress.XtraBars.BarEditItem) If item Is Nothing Then Return End If Select Case TryCast(item.EditValue, String) Case "Company public info" gridControl.DataSource = GridSampleDataList.GetCompanyPublicInfo() Case "Company private info" gridControl.DataSource = GridSampleDataList.GetCompanyPrivateInfo() Case "Product info" gridControl.DataSource = GridSampleDataList.GetProductSample() End Select End Sub
要確?;诋斍翱捎玫臄祿侄沃匦聞?建網格列,請處理事件,該事件在網格每次接收到新數據源時觸發。在事件處理程序中,只需調用 方法即可完成所需的工作。
C#
void gridControl_DataSourceChanged(object sender, EventArgs e) { DevExpress.XtraGrid.GridControl grid = sender as DevExpress.XtraGrid.GridControl; if(grid == null) return; grid.MainView.PopulateColumns(); (grid.MainView as GridView).BestFitColumns(); }
VB.NET
Private Sub gridControl_DataSourceChanged(ByVal sender As Object, ByVal e As EventArgs) Dim grid As DevExpress.XtraGrid.GridControl = TryCast(sender, DevExpress.XtraGrid.GridControl) If grid Is Nothing Then Return End If grid.MainView.PopulateColumns() TryCast(grid.MainView, GridView).BestFitColumns() End Sub
運行應用程序,看看它是如何工作的,應用程序仍然以自動生成的樣例數據啟動。如果您從Ribbon中的下拉列表中選擇一個項目,網格將顯示來自相應數據源的數據。
請注意,所有網格列都顯示了其默認編輯器,并應用了默認格式。例如,Product Info數據包含不能完全查看的多行文本,因為默認的網格單元格編輯器只允許單行文本。Company Public Info數據包括顯示為簡單文本字符串的url和電子郵件,以及理想情況下應該使用電話掩碼格式的電話號碼。最后,Private Company Info顯示不應該立即可見的密碼。
改變這種情況的一種方法是訪問列對象并更新它們的設置,但這意味著每次將數據源綁定到數據感知控件時都應該這樣做。另一種方法是使用Microsoft提供的、大多數DevExpress數據感知控件支持的數據注釋屬性。為了能夠使用這些屬性,請確保您的應用程序引用了System.ComponentModel.DataAnnotations名稱空間。
有兩種方法可以使用這些屬性,第一種也是最簡單的方法是在每個數據字段之前定義所需的屬性,這就是對Product類所做的工作。某些屬性指示數據類型,以便分配適當的單元格編輯器。ReadOnly屬性允許您禁用特定字段的數據編輯,還可以應用數據輸入驗證規則,正如Range屬性所做的那樣。
C#
using System.ComponentModel.DataAnnotations; public class Product { [ReadOnly(true)] public double UnitPrice { get; set; } [EnumDataType(typeof(ProductCategory))] public int Category { get; set; } [Display(Description = "The amount of currently available product")] public int Quantity { get; set; } [DataType(DataType.Text), Display(Order = -1)] public string Text { get; set; } [DataType(DataType.MultilineText)] public string MultilineText { get; set; } [DataType(DataType.Currency), Range(200, 5000)] public int Currency { get; set; } [DataType(DataType.Date)] public DateTime Date { get; set; } [DataType(DataType.Time)] public DateTime Time { get; set; } }
VB.NET
Imports System.ComponentModel.DataAnnotations Public Class Product <[ReadOnly](True)> Public Property UnitPrice() As Double <EnumDataType(GetType(ProductCategory))> Public Property Category() As Integer <Display(Description := "The amount of currently available product")> Public Property Quantity() As Integer <DataType(DataType.Text), Display(Order := -1)> Public Property Text() As String <DataType(DataType.MultilineText)> Public Property MultilineText() As String <DataType(DataType.Currency), Range(200, 5000)> Public Property Currency() As Integer <DataType(DataType.Date)> Public Property [Date]() As Date <DataType(DataType.Time)> Public Property Time() As Date End Class
啟動應用程序,切換到產品信息數據,看看它現在的樣子。多行文本使用MemoEdit單元格編輯器,它允許我們完整地查看文本,而Currency列只允許指定范圍內的數據。
當您擁有多個類中不使用的唯一數據字段時,這種方法非常有用,完成相同任務的另一種方法是使用MetadataType類屬性。使用這種方法,您可以定義一次數據字段屬性,然后將該定義用于多個類。它還可以提高代碼的可讀性,因為數據屬性不必出現在每個屬性定義之前。
Private 和 Public Company Info類都將使用由CompanyProductMetadata類定義的元數據。
C#
[MetadataType(typeof(CompanyProductMetadata))] public class CompanyPublicInfo { // ... } // ... public class CompanyProductMetadata { [Display(ShortName = "Company", Name = "Company Name", AutoGenerateFilter = false)] public object CompanyName; [Display(Order = 2)] public object Country; [Display(Order = 1), Editable(false)] public object City; [DataType(DataType.Url)] public object Url; [DataType(DataType.EmailAddress)] public object Email; [DataType(DataType.PhoneNumber), Required] public object Phone; [DataType(DataType.Text), Display(Order = -1)] public object Text; [Display(AutoGenerateField = false, Description = "This column isn't created")] public object AdditionalInfo; [DataType(DataType.Password), StringLength(20, MinimumLength = 3)] public object Password; // ... }
VB.NET
<MetadataType(GetType(CompanyProductMetadata))> Public Class CompanyPublicInfo ' ... End Class Public Class CompanyProductMetadata <Display(ShortName := "Company", Name := "Company Name", AutoGenerateFilter := False)> Public CompanyName As Object <Display(Order := 2)> Public Country As Object <Display(Order := 1), Editable(False)> Public City As Object <DataType(DataType.Url)> Public Url As Object <DataType(DataType.EmailAddress)> Public Email As Object <DataType(DataType.PhoneNumber), Required> Public Phone As Object <DataType(DataType.Text), Display(Order := -1)> Public Text As Object <Display(AutoGenerateField := False, Description := "This column isn't created")> Public AdditionalInfo As Object <DataType(DataType.Password), StringLength(20, MinimumLength := 3)> Public Password As Object ' ... End Class
運行應用程序來查看結果,切換到Public Company Info數據源,可以看到URL現在顯示為實際的超鏈接,電話號碼使用屏蔽輸入。
本例中的解決方案包括一個數據源文件,該文件有三個提供網格數據的類——CompanyPublicInfo、CompanyPrivateInfo和Product。它們三個的屬性通過使用MetadataType屬性從CompanyProductMetadata類派生數據注釋屬性。最終用戶可以使用表單頂部的編輯器調用Get…方法之一,該方法將用示例數據填充網格。
重要提示:要使用數據注釋屬性,您需要在您的解決方案中引用System.ComponentModel.DataAnnotations庫。
DataSource.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GridDataAttributes { [MetadataType(typeof(CompanyProductMetadata))] public class CompanyPublicInfo { public string CompanyName { get; set; } public string Country { get; set; } public string City { get; set; } public string Url { get; set; } public string Email { get; set; } public string Phone { get; set; } public string AdditionalInfo { get; set; } } [MetadataType(typeof(CompanyProductMetadata))] public class CompanyPrivateInfo { public string Password { get; set; } public DateTime Date2 { get; set; } public double Sales { get; set; } public double Profit { get; set; } public double SalesVsTarget { get; set; } public double MarketShare { get; set; } public double CustomersSatisfaction { get; set; } } public class Product { [ReadOnly(true)] public double UnitPrice { get; set; } [EnumDataType(typeof(ProductCategory))] public int Category { get; set; } [Display(Description = "The amount of currently available product")] public int Quantity { get; set; } [DataType(DataType.Text), Display(Order = -1)] public string Text { get; set; } [DataType(DataType.MultilineText)] public string MultilineText { get; set; } [DataType(DataType.Currency), Range(200, 5000)] public int Currency { get; set; } [DataType(DataType.Date)] public DateTime Date { get; set; } [DataType(DataType.Time)] public DateTime Time { get; set; } } public class CompanyProductMetadata { [Display(ShortName = "Company", Name = "Company Name", AutoGenerateFilter = false)] public object CompanyName; [Display(Order = 2)] public object Country; [Display(Order = 1), Editable(false)] public object City; [DataType(DataType.Url)] public object Url; [DataType(DataType.EmailAddress)] public object Email; [DataType(DataType.PhoneNumber), Required] public object Phone; [DataType(DataType.Text), Display(Order = -1)] public object Text; [Display(AutoGenerateField = false, Description = "This column isn't created")] public object AdditionalInfo; [DataType(DataType.Password), StringLength(20, MinimumLength = 3)] public object Password; [DisplayFormat(DataFormatString = "MMMM/yyyy"), Display(Name = "Date 2")] public object Date2; [DisplayFormat(DataFormatString = "#,##0,,M")] public object Sales; [DisplayFormat(DataFormatString = "#,##0,,M")] public object Profit; [DisplayFormat(DataFormatString = "p", ApplyFormatInEditMode = true), Display(Name = "Sales vs Target")] public object SalesVsTarget; [DisplayFormat(DataFormatString = "p0", ApplyFormatInEditMode = false)] public object MarketShare; [Display(Name = "Cust Satisfaction")] public object CustomersSatisfaction; } public enum ProductCategory { Beverages = 1, Fruit = 2, Vegetables = 3, Meat = 4, Condiments = 5, Confections = 6, DairyProducts = 7, GrainsCereals = 8, Seafood = 9 } public class GridSampleDataList { static public List<CompanyPrivateInfo> GetCompanyPrivateInfo() { return new List<CompanyPrivateInfo> { new CompanyPrivateInfo() { CustomersSatisfaction = 3.1, Date2 = DateTime.Now, MarketShare = 42, Password = "123qwerty", Profit = 4951515, Sales = 311414134, SalesVsTarget = 0.0277, } }; } static public List<CompanyPublicInfo> GetCompanyPublicInfo() { return new List<CompanyPublicInfo> { new CompanyPublicInfo() { AdditionalInfo = "Some Info", City = "Glendale", CompanyName = "Developer Express", Country = "USA", Email = "info@devexpress.com", Phone = "1234567890", Url = "www.devexpress.com", } }; } static public List<Product> GetProductSample() { return new List<Product> { new Product() { Currency = 1000, Category = 2, Date = DateTime.Now, MultilineText = "Line1\r\nLine2\r\nLine3", Quantity = 321, Text = "Sample Text", Time = DateTime.Now, UnitPrice = 1800, } }; } } }
Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid; namespace GridDataAttributes { public partial class Form1 : XtraForm { public Form1() { InitializeComponent(); gridView1.OptionsView.ShowGroupPanel = false; gridControl1.DataSourceChanged += gridControl1_DataSourceChanged; } void gridControl1_DataSourceChanged(object sender, EventArgs e) { gridControl1.MainView.PopulateColumns(); (gridControl1.MainView as GridView).BestFitColumns(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); //gridControl1.DataSource = CompanyProductList.GetSampleData(); //companyProductListBindingSource.DataSource = CompanyProductList.GetSampleData(); //companyProductBindingSource.DataSource = CompanyProductList.GetSampleData(); } private void barEditItem3_EditValueChanged(object sender, EventArgs e) { switch (barEditItem3.EditValue as string) { case "Company public info": gridControl1.DataSource = GridSampleDataList.GetCompanyPublicInfo(); break; case "Company private info": gridControl1.DataSource = GridSampleDataList.GetCompanyPrivateInfo(); break; case "Product info": gridControl1.DataSource = GridSampleDataList.GetProductSample(); break; } } } }
Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.Skins; namespace GridDataAttributes { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { SkinManager.EnableFormSkins(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }
Program.vb
Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Threading.Tasks Imports System.Windows.Forms Imports DevExpress.Skins Namespace GridDataAttributes Friend NotInheritable Class Program Private Sub New() End Sub ''' <summary> ''' The main entry point for the application. ''' </summary> <STAThread> _ Shared Sub Main() SkinManager.EnableFormSkins() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Application.Run(New Form1()) End Sub End Class End Namespace
Form1.vb
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Text Imports System.Threading.Tasks Imports System.Windows.Forms Imports DevExpress.XtraEditors Imports DevExpress.XtraGrid.Views.Grid Namespace GridDataAttributes Partial Public Class Form1 Inherits XtraForm Public Sub New() InitializeComponent() gridView1.OptionsView.ShowGroupPanel = False AddHandler gridControl1.DataSourceChanged, AddressOf gridControl1_DataSourceChanged End Sub Private Sub gridControl1_DataSourceChanged(ByVal sender As Object, ByVal e As EventArgs) gridControl1.MainView.PopulateColumns() TryCast(gridControl1.MainView, GridView).BestFitColumns() End Sub Protected Overrides Sub OnLoad(ByVal e As EventArgs) MyBase.OnLoad(e) 'gridControl1.DataSource = CompanyProductList.GetSampleData(); 'companyProductListBindingSource.DataSource = CompanyProductList.GetSampleData(); 'companyProductBindingSource.DataSource = CompanyProductList.GetSampleData(); End Sub Private Sub barEditItem3_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles barEditItem3.EditValueChanged Select Case TryCast(barEditItem3.EditValue, String) Case "Company public info" gridControl1.DataSource = GridSampleDataList.GetCompanyPublicInfo() Case "Company private info" gridControl1.DataSource = GridSampleDataList.GetCompanyPrivateInfo() Case "Product info" gridControl1.DataSource = GridSampleDataList.GetProductSample() End Select End Sub End Class End Namespace
DataSource.vb
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.ComponentModel.DataAnnotations Imports System.Linq Imports System.Text Imports System.Threading.Tasks Namespace GridDataAttributes <MetadataType(GetType(CompanyProductMetadata))> _ Public Class CompanyPublicInfo Public Property CompanyName() As String Public Property Country() As String Public Property City() As String Public Property Url() As String Public Property Email() As String Public Property Phone() As String Public Property AdditionalInfo() As String End Class <MetadataType(GetType(CompanyProductMetadata))> _ Public Class CompanyPrivateInfo Public Property Password() As String Public Property Date2() As Date Public Property Sales() As Double Public Property Profit() As Double Public Property SalesVsTarget() As Double Public Property MarketShare() As Double Public Property CustomersSatisfaction() As Double End Class Public Class Product <[ReadOnly](True)> _ Public Property UnitPrice() As Double <EnumDataType(GetType(ProductCategory))> _ Public Property Category() As Integer <Display(Description := "The amount of currently available product")> _ Public Property Quantity() As Integer <DataType(DataType.Text), Display(Order := -1)> _ Public Property Text() As String <DataType(DataType.MultilineText)> _ Public Property MultilineText() As String <DataType(DataType.Currency), Range(200, 5000)> _ Public Property Currency() As Integer <DataType(DataType.Date)> _ Public Property [Date]() As Date <DataType(DataType.Time)> _ Public Property Time() As Date End Class Public Class CompanyProductMetadata <Display(ShortName := "Company", Name := "Company Name", AutoGenerateFilter := False)> _ Public CompanyName As Object <Display(Order := 2)> _ Public Country As Object <Display(Order := 1), Editable(False)> _ Public City As Object <DataType(DataType.Url)> _ Public Url As Object <DataType(DataType.EmailAddress)> _ Public Email As Object <DataType(DataType.PhoneNumber), Required> _ Public Phone As Object <DataType(DataType.Text), Display(Order := -1)> _ Public Text As Object <Display(AutoGenerateField := False, Description := "This column isn't created")> _ Public AdditionalInfo As Object <DataType(DataType.Password), StringLength(20, MinimumLength := 3)> _ Public Password As Object <DisplayFormat(DataFormatString := "MMMM/yyyy"), Display(Name := "Date 2")> _ Public Date2 As Object <DisplayFormat(DataFormatString := "#,##0,,M")> _ Public Sales As Object <DisplayFormat(DataFormatString := "#,##0,,M")> _ Public Profit As Object <DisplayFormat(DataFormatString := "p", ApplyFormatInEditMode := True), Display(Name := "Sales vs Target")> _ Public SalesVsTarget As Object <DisplayFormat(DataFormatString := "p0", ApplyFormatInEditMode := False)> _ Public MarketShare As Object <Display(Name := "Cust Satisfaction")> _ Public CustomersSatisfaction As Object End Class Public Enum ProductCategory Beverages = 1 Fruit = 2 Vegetables = 3 Meat = 4 Condiments = 5 Confections = 6 DairyProducts = 7 GrainsCereals = 8 Seafood = 9 End Enum Public Class GridSampleDataList Public Shared Function GetCompanyPrivateInfo() As List(Of CompanyPrivateInfo) Return New List(Of CompanyPrivateInfo) From { _ New CompanyPrivateInfo() With {.CustomersSatisfaction = 3.1, .Date2 = Date.Now, .MarketShare = 42, .Password = "123qwerty", .Profit = 4951515, .Sales = 311414134, .SalesVsTarget = 0.0277} _ } End Function Public Shared Function GetCompanyPublicInfo() As List(Of CompanyPublicInfo) Return New List(Of CompanyPublicInfo) From { _ New CompanyPublicInfo() With {.AdditionalInfo = "Some Info", .City = "Glendale", .CompanyName = "Developer Express", .Country = "USA", .Email = "info@devexpress.com", .Phone = "1234567890", .Url = "www.devexpress.com"} _ } End Function Public Shared Function GetProductSample() As List(Of Product) Return New List(Of Product) From { _ New Product() With {.Currency = 1000, .Category = 2, .Date = Date.Now, .MultilineText = "Line1" & ControlChars.CrLf & "Line2" & ControlChars.CrLf & "Line3", .Quantity = 321, .Text = "Sample Text", .Time = Date.Now, .UnitPrice = 1800} _ } End Function End Class End Namespace
更多產品資訊及授權,歡迎“”!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網