Data binding 自定义DataGridViewColumn(WinForms)中多个文件的自定义绑定

Data binding 自定义DataGridViewColumn(WinForms)中多个文件的自定义绑定,data-binding,datagridview,datagridviewcolumn,Data Binding,Datagridview,Datagridviewcolumn,我有一个关于自定义DataGridViewColumn的数据绑定(多个属性)的问题。 下面是我拥有的控件的模式,我需要使其与DataGridView数据源绑定。有没有关于讨论这个问题的文章的想法或链接 控件 图形控件(自定义):显示在 custrom DataGridView列。有 属性,如“开始日期”, “EndDate”,Windows图表控件, 它本身是可装订的 自定义单元格(DataGridViewCustomCell继承 从DataGridViewCell)保存 图形控件和一些进程

我有一个关于自定义DataGridViewColumn的数据绑定(多个属性)的问题。 下面是我拥有的控件的模式,我需要使其与DataGridView数据源绑定。有没有关于讨论这个问题的文章的想法或链接

控件

  • 图形控件(自定义):显示在 custrom DataGridView列。有 属性,如“开始日期”, “EndDate”,Windows图表控件, 它本身是可装订的
  • 自定义单元格(DataGridViewCustomCell继承 从DataGridViewCell)保存 图形控件和一些进程 事件(例如,OneNet事件, 将焦点传递给自定义图形 用于拖放类型的列 事件等)
  • 自定义列(DataGridViewCustomColumn) 从DataGridViewColumn继承) 定义单元模板类型的: CellTemplate=新 DataGridViewCustomCell();也是一个 数据绑定的主要选择
数据结构:

  • 要在其他DataGridView列中显示的主表
  • 图表表-通过父子关系与主表相关。保存图形数据
  • 通过父子关系与图形表相关的图表表。保存win form图表的数据,win form图表是我的图形控件的一部分
到目前为止,我甚至无法通过图形控件或图形保持列/单元格将图形表中的数据绑定到

见我的问题

这很容易做到,只是不需要使用IDE来完成,而是通过代码来完成。这是一个很大的工作,但如果你知道自己在做什么,就没有那么困难了。不到一天的时间里,我从一无所知变成了能够做到这一点,所以我相信你一定能做到


编辑:您还可以在填充datagridview的sql中使用联接。谢谢您的回答。我的数据源不是SQL数据源,事实上,我所说的是针对win forms的datagridview(我不确定这是否清楚)

由于我在任何论坛上都没有得到回答,我想,我会为那些可能有类似问题的人和可能的批评概述我提出的解决方案。:-)

(著名的MS示例中也解释了步骤1-2) 1.创建从DataGridViewColumn和DataGridViewCell继承的自己的类,设置列模板; 2.创建“自定义编辑”控件

  • 在数据项(无论是数据行还是列表项)中,添加一个只读属性,该属性返回对象本身。此属性已绑定到自定义列 自定义单元格:

    public partial class MyCell : DataGridViewCell 
     {
        protected override void Paint(...)
            {...} // draws control
                  // receives data item as a value 
                  // in my case I have to custom-draw entire control in this fnc.
        public override void InitializeEditingControl(...)
            {...} // initialize control editing
        // override some other properties
        public override Type EditType {
            get{ 
               return typeof(MyEditControl);
            }
        }
        public override Type ValueType{
            get{
               return typeof(MyItem);
            }
        }
     }
    
    自定义列:

    public partial class MyColumn : DataGridViewColumn
    {
        public MyColumn(){ ...
        CellTemplate = new MyCell();
        }
    }
    
    编辑控件:

    public partial class MyEditControl : UserControl, IDataGridViewEditingControl
    {... // implements IDataGridViewEditingControl
         // value is our data item
    }
    
    数据项,则数据源成为列表

    public class MyItem:Object{
        ...
        [XmlIgnore] // I need it because I do serialization
        public MyItem Self {
            get {
                return this;
            }
        }
     }