I have a cell containing a custom editor. It is simply a Microsoft Chart embedded into the ControlContainerEditor.RenderingControl. It displays fine. But no mouse events are handled by the chart handler. I suspect that MouseMove for example is being eaten by the grid control.
Is there a way to get the chart events to fire to the handler?
This is my code inside the grid InitializeRow event handler.
Chart chart = new Chart();chart.MouseMove += Chart_MouseMove;
ControlContainerEditor editor = new ControlContainerEditor();editor.RenderingControl = chart;editor.ApplyOwnerAppearanceToEditingControl = false;editor.ApplyOwnerAppearanceToRenderingControl = false;editor.EditingControlPropertyName = "Value";editor.RenderingControlPropertyName = "Value";e.Row.Cells["Chart"].Editor = editor;
Hi Joseph,
That makes sense. I thought about suggesting something like that, but there are some significant down-sides to this approach (which may or may not matter to you depending on your application requirements).
For example, suppose the user clicks on another cell (aside from the chart column) - let's say a text cell. And they start typing into that cell to change the value. While they are typing, they realize the mouse is in the way, so they move the mouse and it happens to go over the chart column. This is going to try to enter the chart column into edit mode and thus exit edit mode on the current cell - which the user was in the middle of editing. So it's goin to exit edit mode and try to save the partially-edited value into that cell - which may not even be valid, since they didn't finish editing it.
Maybe that's not important - maybe you don't have any other editable columns, in which case, it's no big deal.
I found a solution.
Set the editor.EditingControl with an instance of the chart (same codes generates the chart for the RenderingControl)
Now I can wire up my events and get them when in editing mode AND the chart is properly rendered.
To solve the problem of not getting event except in edit mode, I use the grid mouse over event. When the mouse is over the cell hosting the chart I activate the cell and call grid.PerformAction(EnterEditMode). Now as I move the mouse over the chart I receive the mouse move events and all works!
Hi,
This is not going to be possible.
josephsimpkins said:I suspect that MouseMove for example is being eaten by the grid control.
That's not correct - it's actually even worse than that. The way the ControlContainerEditor works is that when a cell renders, it basically assigns the Value of the cell to your RenderingControl, then it calls DrawToBitmap on that control and simply draws the image in the cell. So the grid isn't eating the messages, there's no control there to receive messages in the first place, it's just a picture of that control.
The only time the control is interactive at all is for the EditingControl for the cell currently in edit mode. In that case, the actual control is positioned over the grid and it will get messages, but only one cell can be in edit mode at a time.
So you are never going to get MouseMove messages over the embedded controls for every cell. Realisitcally, this would be problematic for several reasons. For one thing, there is only one single instance of the RenderingControl. For what you want to happen, you would need one for every cell. That would be very innefficient in terms of memory usage. It would also be slower to render since