locked
custom control in DataGridView Cells RRS feed

  • Question

  • Hi,

    I want to add a custom control to the datagridview, and I was looking at this thread http://social.msdn.microsoft.com/Forums/windows/en-US/ea8c8859-70d0-48d2-bc9a-5d6c21ac135e/host-controls-in-windows-forms-datagridview-cells which has helped me.

    My question is that in my situation the controls are created separate from the datagrid code, they are actually charts (DataVisualization.Charting.Chart), they get created independently somewhere else, and I want to add them to the datagridview. They are also different for different rows, so a unique chart for every row, and hence a unique DrawtoBitmap called for each row. I want to add them in a way so that I keep on adding new rows, and they keep on displaying. So I will need to pass them to the rows somehow. My understanding of all this code, the class and the inheritance is still really new, so I cant get my head around this code, so I need suggestion on how to go about implementing this. In the code that I mentioned in the other thread, please suggest what should my approach be so that existing chart controls can become a part of the code in the other thread.

    waiting for your reply, thanks

    ..ab


    Ab

    Monday, June 9, 2014 10:54 AM

Answers

  • Hello,

    I would look at it this way, the custom column should be similar to an image column in that an image column is indeed different for each row and that each image can be different i.e. JPEG, BMP etc. but the base is the same which boil down to a byte array that represents an image. So your custom column would follow suit, a valid object for the column would have a base of chart.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Proposed as answer by Carl Cai Monday, June 16, 2014 1:27 AM
    • Marked as answer by Barry Wang Monday, June 16, 2014 9:35 AM
    Monday, June 9, 2014 3:47 PM
  • Hi,

    Thanks for the reply. I'm confused with this thing that how I can prevent the control (which inherits from IDataGridViewEditingControl) stop from getting created automatically. I do not want any datagridview, or the cell or anything to be creating it, instead I want to supply my own of it.

    Shortly, did you mean as following image?

    If so, then I agree with Kevininstructorwhich is somehow like a image column.

    >>you see up there its gone to the activator.CreateInstance, I really do not want that! I want to supply my own already made chart control. <<

    I am afraid that this is impossible to stop getting that happen unless you develop a datagridview by yourself, for what I could suggest is disable the feature adding new rows inside datagridview, just add another button outside datagridview, and add a event handler to that button to add new rows to that datagridview, before adding these rows just creatd in that handler, change the cell of that row to the chart depends on your requirements.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Carl Cai Monday, June 16, 2014 1:26 AM
    • Marked as answer by Barry Wang Monday, June 16, 2014 9:35 AM
    Wednesday, June 11, 2014 10:10 AM

All replies

  • Hello,

    I would look at it this way, the custom column should be similar to an image column in that an image column is indeed different for each row and that each image can be different i.e. JPEG, BMP etc. but the base is the same which boil down to a byte array that represents an image. So your custom column would follow suit, a valid object for the column would have a base of chart.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Proposed as answer by Carl Cai Monday, June 16, 2014 1:27 AM
    • Marked as answer by Barry Wang Monday, June 16, 2014 9:35 AM
    Monday, June 9, 2014 3:47 PM
  • Thanks for the reply. I'm confused with this thing that how I can prevent the control (which inherits from IDataGridViewEditingControl) stop from getting created automatically. I do not want any datagridview, or the cell or anything to be creating it, instead I want to supply my own of it. Lets say I have a lot of charts (yes I get a wrapper and inherit it from IDataGridViewEditingControl so it can go inside a datagridview) in an array, and with each create of a new row in datagridview, I want to "supply" my own control/chart that was already created and is living inside the array. Talking in code please guide on how to do this cuz I'm lost. What method/property of what class/interface would allow me to supply an already created control that the cell should play with, rather it going and doing its own creation. If there is any confusion in my question plz let me know.

    Ab



    • Edited by developer1 Tuesday, June 10, 2014 5:56 AM
    Tuesday, June 10, 2014 5:53 AM
  • for example, when the mouse is clicked on the cell, following are the methods is goes through:

    System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
    System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
    System.Windows.Forms.SecurityUtils.SecureCreateInstance(Type type, Object[] args, Boolean allowNonPublic)
    System.Windows.Forms.DataGridView.BeginEditInternal(Boolean selectAll)
    System.Windows.Forms.DataGridView.BeginEdit(Boolean selectAll)
    System.Windows.Forms.DataGridViewTextBoxCell.OnMouseClick(DataGridViewCellMouseEventArgs e)
    System.Windows.Forms.DataGridView.OnCellMouseClick(DataGridViewCellMouseEventArgs e)
    System.Windows.Forms.DataGridView.OnMouseClick(MouseEventArgs e)

    you see up there its gone to the activator.CreateInstance, I really do not want that! I want to supply my own already made chart control.

    I really hope someone can shed some light on this.


    Ab

    Tuesday, June 10, 2014 9:40 AM
  • Hi,

    Thanks for the reply. I'm confused with this thing that how I can prevent the control (which inherits from IDataGridViewEditingControl) stop from getting created automatically. I do not want any datagridview, or the cell or anything to be creating it, instead I want to supply my own of it.

    Shortly, did you mean as following image?

    If so, then I agree with Kevininstructorwhich is somehow like a image column.

    >>you see up there its gone to the activator.CreateInstance, I really do not want that! I want to supply my own already made chart control. <<

    I am afraid that this is impossible to stop getting that happen unless you develop a datagridview by yourself, for what I could suggest is disable the feature adding new rows inside datagridview, just add another button outside datagridview, and add a event handler to that button to add new rows to that datagridview, before adding these rows just creatd in that handler, change the cell of that row to the chart depends on your requirements.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Carl Cai Monday, June 16, 2014 1:26 AM
    • Marked as answer by Barry Wang Monday, June 16, 2014 9:35 AM
    Wednesday, June 11, 2014 10:10 AM