FlexGrid for WinForm 采用了最新的数据绑定技术,并与Microsoft .NET Framework无缝集成。 所以,您能够得到易于使用的灵活网格控件,用于建立用户友好界面,以显示、编辑、格式化、组织、汇总和打印表格数据。html
FlexGrid的DataMap属性容许您实现“已翻译”的行或列。在转换的行或列中,网格不显示存储在单元格中的值。相反,它会在列的DataMap中查找这些值并显示映射的值。安全
有时您可能须要在C1FlexGrid / C1FlexGridClassic中使用DataMap来显示项目列表。即便列表包含大量数据,其加载也是平滑且即时的。在本文中,咱们将讨论如何使用自定义ComboBox编辑器以加快DataMap网格的加载时间。编辑器
全部内置网格编辑器都实现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是一款专一于企业应用高性能开发的 .NET 全功能控件套包,包含300余种控件,支持7大平台,涵盖7大功能模块。较于市面上其余同类产品,ComponentOne更加轻盈,功能更增强大,20多年的开发经验,将为您的应用系统带来更为安全的使用体验。纯中文操做界面,一对一技术支持,厂商级的技术服务,共同造就了这款国际顶级控件套包。code
您对ComponentOne 产品的任何技术问题,都有技术支持工程师提供1对1专业解答,点击此处便可发帖提问>> 技术支持论坛component