1. 程式人生 > >【.NET開發之美】使用ComponentOne提高.NET DataMap中的載入速度

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

概述

  1. FlexGrid for WinForm 採用了最新的資料繫結技術,並與Microsoft .NET Framework無縫整合。 因此,您可以獲得易於使用的靈活網格控制元件,用於建立使用者友好介面,以顯示編輯格式化組織彙總和打印表格資料。

  2. FlexGrid的DataMap屬性允許您實現“已翻譯”的行或列。在轉換的行或列中,網格不顯示儲存在單元格中的值。相反,它會在列的DataMap中查詢這些值並顯示對映的值。

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

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

所有內建網格編輯器都實現IC1EmbeddedEditor介面,ComponentOne Input庫中的控制元件也是如此。 如果我們想要使用帶有C1FlexGrid的第三方編輯器,我們需要建立一個派生類並實現此介面。

實現步驟

建立一個模型類MyComboItem來繫結ComboBox。

public class MyComboItem

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

建立一個自定義控制元件MyComboBox,它繼承ComboBox類並實現IC1EmbeddedEditor介面。

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.

關於ComponentOne Enterprise

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

關於葡萄城

賦能開發者!葡萄城公司成立於 1980 年,是全球領先的集開發工具、商業智慧解決方案、管理系統設計工具於一身的軟體和服務提供商。西安葡萄城是其在中國的分支機構,面向全球市場提供軟體研發服務,併為中國企業的資訊化提供國際先進的開發工具、軟體和研發諮詢服務。葡萄城的控制元件和軟體產品在國內外屢獲殊榮,在全球被數十萬家企業、學校和政府機構廣泛應用。