【.NET開發之美】使用ComponentOne提升.NET DataMap中的加載速度

概述

  1. FlexGrid for WinForm 採用了最新的數據綁定技術,並與Microsoft .NET Framework無縫集成。 所以,您能夠得到易於使用的靈活網格控件,用於建立用戶友好界面,以顯示、編輯、格式化、組織、彙總和打印表格數據。html

  2. FlexGrid的DataMap屬性容許您實現「已翻譯」的行或列。在轉換的行或列中,網格不顯示存儲在單元格中的值。相反,它會在列的DataMap中查找這些值並顯示映射的值。安全

  3. 有時您可能須要在C1FlexGrid / C1FlexGridClassic中使用DataMap來顯示項目列表。即便列表包含大量數據,其加載也是平滑且即時的。在本文中,咱們將討論如何使用自定義ComboBox編輯器以加快DataMap網格的加載時間。編輯器

建立編輯器並在Grid中託管它

全部內置網格編輯器都實現IC1EmbeddedEditor接口,ComponentOne Input庫中的控件也是如此。 若是咱們想要使用帶有C1FlexGrid的第三方編輯器,咱們須要建立一個派生類並實現此接口。性能

實現步驟

建立一個模型類MyComboItem來綁定ComboBox。flex

public class MyComboItemthis

{ public int Id { get; set; } public string Display { get; set; } } { public int Id { get; set; } public string Display { get; set; } }

建立一個自定義控件MyComboBox,它繼承ComboBox類並實現IC1EmbeddedEditor接口。spa

public partial class MyComboBox : ComboBox, IC1EmbeddedEditor { public MyComboBox() { InitializeComponent(); } #region IC1EmbeddedEditor-Members // Initialize editor: select transferred value public void C1EditorInitialize(object value, IDictionary editorAttributes) { this.SelectedValue = value; } //Get value from editor public object C1EditorGetValue() { return (base.SelectedItem as MyComboItem)?.Id; } //Value is always TRUE public bool C1EditorValueIsValid() { return true; } //Adjust editor size public void C1EditorUpdateBounds(Rectangle rc) { if (rc.Height != -1 && rc.Width != -1) { this.Location = new Point(rc.X, rc.Y); this.Width = rc.Width; this.Height = this.DefaultSize.Height; } else { //Editor has scrolled out of the picture. Take over the height / width of -1. this.Width = -1; this.Height = -1; } } //TRUE if Escape or Enter public bool C1EditorKeyDownFinishEdit(KeyEventArgs e) { if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Enter) return true; return false; } //Format and editor value public string C1EditorFormat(object value, string mask) { return null; } //Style of Editors public UITypeEditorEditStyle C1EditorGetStyle() { return UITypeEditorEditStyle.DropDown; } #endregion } } public partial class MyComboBox : ComboBox, IC1EmbeddedEditor { public MyComboBox() { InitializeComponent(); } #region IC1EmbeddedEditor-Members // Initialize editor: select transferred value public void C1EditorInitialize(object value, IDictionary editorAttributes) { this.SelectedValue = value; } //Get value from editor public object C1EditorGetValue() { return (base.SelectedItem as MyComboItem)?.Id; } //Value is always TRUE public bool C1EditorValueIsValid() { return true; } //Adjust editor size public void C1EditorUpdateBounds(Rectangle rc) { if (rc.Height != -1 && rc.Width != -1) { this.Location = new Point(rc.X, rc.Y); this.Width = rc.Width; this.Height = this.DefaultSize.Height; } else { //Editor has scrolled out of the picture. Take over the height / width of -1. this.Width = -1; this.Height = -1; } } //TRUE if Escape or Enter public bool C1EditorKeyDownFinishEdit(KeyEventArgs e) { if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Enter) return true; return false; } //Format and editor value public string C1EditorFormat(object value, string mask) { return null; } //Style of Editors public UITypeEditorEditStyle C1EditorGetStyle() { return UITypeEditorEditStyle.DropDown; } #endregion } }

建立MyComboBox類的實例,並將其分配給網格的列編輯器,以下所示:翻譯

Dictionary<int, string> DMap = new Dictionary<int, string>(); ComboBox c1 = new MyComboBox(); List<MyComboItem> _list = new List<MyComboItem>(); c1.DataSource = _list; c1.ValueMember = "Id"; c1.DisplayMember = "Display"; _flex.Cols[2].Editor = c1; _flex.Cols[2].DataMap = DMap; //use DataMap to show IDs as values. Dictionary<int, string> DMap = new Dictionary<int, string>(); ComboBox c1 = new MyComboBox(); List<MyComboItem> _list = new List<MyComboItem>(); c1.DataSource = _list; c1.ValueMember = "Id"; c1.DisplayMember = "Display"; _flex.Cols[2].Editor = c1; _flex.Cols[2].DataMap = DMap; //use DataMap to show IDs as values.

ComponentOne Enterprise | 下載試用

ComponentOne是一款專一於企業應用高性能開發的 .NET 全功能控件套包,包含300餘種控件,支持7大平臺,涵蓋7大功能模塊。較於市面上其餘同類產品,ComponentOne更加輕盈,功能更增強大,20多年的開發經驗,將爲您的應用系統帶來更爲安全的使用體驗。純中文操做界面,一對一技術支持,廠商級的技術服務,共同造就了這款國際頂級控件套包。code

您對ComponentOne 產品的任何技術問題,都有技術支持工程師提供1對1專業解答,點擊此處便可發帖提問>> 技術支持論壇component

相關文章
相關標籤/搜索