轉(zhuǎn)帖|使用教程|編輯:龔雪|2015-12-18 09:29:02.000|閱讀 937 次
概述:本文主要介紹如何快速的使用C1DataGrid for WPF做最簡(jiǎn)單的數(shù)據(jù)綁定。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
本文主要介紹如何快速的使用C1DataGrid for WPF做最簡(jiǎn)單的數(shù)據(jù)綁定。
為了創(chuàng)建工程并添加C1DataGrid,需要遵循如下步驟:
上面我們已經(jīng)添加了一個(gè)C1DataGrid控件,在這里需要為之后在C1DataGrid控件里展示的數(shù)據(jù)提供數(shù)據(jù)模型。通過(guò)如下步驟,添加一個(gè)數(shù)據(jù)模型:
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數(shù)據(jù)模型的基礎(chǔ)上,使用這個(gè)模型產(chǎn)生一個(gè)數(shù)據(jù)對(duì)象集合,然后設(shè)置這個(gè)列表展示在C1DataGrid里。步驟如下:
List _products = new List (); for(int i = 0; i < 100; i++) { _products.Add(new Product()); }
ProductsDataGrid.ItemsSource = _products.
運(yùn)行工程,結(jié)果如下所示:
在表頭直接點(diǎn)擊可以實(shí)現(xiàn)排序,并且在表頭下拉框可以實(shí)現(xiàn)Filter過(guò)濾等功能。
上面的代碼請(qǐng)參考:
2015歲末掃尾之戰(zhàn)!全球廠商攜手放利!優(yōu)惠詳情點(diǎn)擊查看>>
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)