轉帖|使用教程|編輯:龔雪|2015-12-18 09:29:02.000|閱讀 937 次
概述:本文主要介紹如何快速的使用C1DataGrid for WPF做最簡單的數據綁定。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
本文主要介紹如何快速的使用C1DataGrid for WPF做最簡單的數據綁定。
為了創建工程并添加C1DataGrid,需要遵循如下步驟:
上面我們已經添加了一個C1DataGrid控件,在這里需要為之后在C1DataGrid控件里展示的數據提供數據模型。通過如下步驟,添加一個數據模型:
public class Product { static Random _rnd = new Random(); static string[] _names = "Macko|Surfair|Pocohey|Studeby".Split('|'); static string[] _lines = "Computers|Washers|Stoves|Cars".Split('|'); static string[] _colors = "Red|Green|Blue|White".Split('|'); public Product() { Name = _names[_rnd.Next() % _names.Length]; Line = _lines[_rnd.Next() % _lines.Length]; Color = _colors[_rnd.Next() % _colors.Length]; Price = 30 + _rnd.NextDouble() * 1000; Cost = 3 + _rnd.NextDouble() * 300; Discontinued = _rnd.NextDouble() < .2; Introduced = DateTime.Today.AddDays(_rnd.Next(-600, 0)); } public string Name { get; set; } public string Color { get; set; } public string Line { get; set; } public double Price { get; set; } public double Cost { get; set; } public DateTime Introduced { get; set; } public bool Discontinued { get; set; } }
在Product數據模型的基礎上,使用這個模型產生一個數據對象集合,然后設置這個列表展示在C1DataGrid里。步驟如下:
List _products = new List (); for(int i = 0; i < 100; i++) { _products.Add(new Product()); }
ProductsDataGrid.ItemsSource = _products.
運行工程,結果如下所示:
在表頭直接點擊可以實現排序,并且在表頭下拉框可以實現Filter過濾等功能。
上面的代碼請參考:
2015歲末掃尾之戰!全球廠商攜手放利!優惠詳情點擊查看>>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網