views:

2243

answers:

2

Hello, I have a question regarding a data binding(of multiple properties) for custom DataGridViewColumn. Here is a schema of what controls that I have, and I need to make it bindable with DataGridView datasource. Any ideas or a link to an article discussing the matter?

Controls

  • Graph Control(custom): Displayed in the custrom DataGridView column. Has properties like "Start Date", "EndDate", Windows Chart control, which is itself, bindable, etc.
  • Custom cell(DataGridViewCustomCell inherits from DataGridViewCell) that holds the Graph control and processes some events(OnEnter event, for example, passes the focus to the custom Graph column for drag-n-drop type of events, etc.)
  • Custom column(DataGridViewCustomColumn inherits from DataGridViewColumn) that defined the cell template type: CellTemplate = new DataGridViewCustomCell(); and also a primary choice for data binding

Data Structure:

  • Main table to be displayed in other DataGridView Columns
  • Graph table - related to the Main table via parent-child relationship. Holds graph data
  • Chart table related to the graph table via parent-child relationship. Holds data for the win-form chart, which is a part of my Graph control.

So far I cannot even bind data from the Graph table to by Graph control or Graph-holding Column/Cell.

A: 

See my question Here

It's easy to do, you just don't use the IDE to do it, you do it all in code. It's a lot of work, but it's not that difficult if you know what your doing. I went from knowing nothing to being able to do it in less than a day so I'm sure you'll be able to do it.

Edit: you can also use a Join in the sql that populates the datagridview

Malfist
A: 

Thank you for your answer. My data sources is not a SQL data source, and as a matter of fact I was talking about datagridview for win-forms(I'm not sure that was clear).

As I did not get the reply on any of the forums I was asking the question, I figured, I would outline a solution I came up with, for those who may have a similar problem and for possible critique. :-)

(steps 1-2 are also explained in the famous MS example) 1. Create your own classes that inherit from DataGridViewColumn and DataGridViewCell, setup the column template; 2. Create your "CustomEdit" control

  1. In the data item, whatever that is, a DataRow, or a List item, add a read-only property, that return the object itself. This property is bound to the custom column.

Custom Cell:

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);
        }
    }
 }

Custom Column:

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

Edit Control:

public partial class MyEditControl : UserControl, IDataGridViewEditingControl
{... // implements IDataGridViewEditingControl
     // value is our data item
}

Data Item, the data sources becomes List<MyItem>

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