继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

【.NET开发之美】使用ComponentOne提高.NET DataMap中的加载速度

葡萄城控件
关注TA
已关注
手记 195
粉丝 56
获赞 338

概述

  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.

了解更多

ActiveReports: 全面满足 .NET 报表开发需求
https://img1.mukewang.com/5bdab52400016c6807930534.jpg

ComponentOne Enterprise:.NET开发的“瑞士军刀”,功能全面、简单易用的 Visual Studio 组件集
https://img.mukewang.com/5bdab58400010a4307070428.jpg


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP