We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Unresponsive Custom Control

Hi, So this CellType = Control thing is just not working out for me. In general, unless the Cell (of type Control) in active, none of the subcomponents are responsive at all (they don''t highlight for mousehover events, nor do they receive click events, etc). Not only that, but when a "Control" cell is activated, the grid itself loses focus - something that doesn''t happen for any other type of cell. As far as I understand it, this is because for "Control" type cells, when they are inactive a snapshot is taken and they are actually drawn as a bitmap - so the subcomponents are no longer really there, rather it''s just a picture of those subcomponents. However it''s done, what I need is a cell type that allows me to put into it whatever type of Syncfusion.Windows.Forms or System.Windows.Forms object that I want, and have them respond to user events even when the cell isn''t active, and not take focus away from the grid when the cell is active. What do I need to do to accomplish such a thing? Thanks much!

21 Replies

AD Administrator Syncfusion Team September 30, 2005 12:53 PM UTC

You will have to derive your own celltype. Take a look at the \Syncfusion\Essential Studio\3.3.0.0\Windows\Grid.Windows\Samples\CellTypes\CalendarCells sample as an initial start at doing this. If you have many child controls in your cell, then you will likely have to do additional work to explicitly put the focus on a particular child control when you user clicks the cell.


CN Clinton Nielsen September 30, 2005 05:42 PM UTC

That example isn''t at all what I''m looking for I''m afraid. The derived celltype in that example still isn''t responsive. It does respond to the click event, but nothing else. Take for example, the built in types "ComboBox", or "CheckBox". The combobox/checkbox in these built in types respond to everything. Try hovering the mouse over cells of that type as an example - you''ll notice they highlight. If, on the other hand, you use the CellType "Control", and put in a single button. That button won''t react to anything at all unless the associated cell is current and active. What exactly is different between those cell types and the "Control" celltype that makes it behave so differently? What I would like is an exact copy of the responsivenes that all of the built in CellTypes have *except* "Control". Thanks.


AD Administrator Syncfusion Team October 1, 2005 03:38 AM UTC

You have to derive your own cell control as I suggested above. The CalendarCell sample does respond to click. If you want more mouse responsiveness, then take a look at the DerivedCellControl Tutorial in the grid user''s guide. It shows you how to have your derived cell respond to mouse actions like hover. That sample shows how to derive a linklabel cell that handles mouse actions so give you feedback as you hover over the label.


CN Clinton Nielsen October 7, 2005 03:55 PM UTC

Okay, here''s my situation. In one of my cells, I have a Custom Control (Actually a Windows.Forms.UserControl), that itself has Buttons, and a TabControl, and on that TabControl''s pages there are GridControls. These GridControls themselves may have cells with all of the above inside them. I need all of these things to be perfectly responsive to all mouse events. According to what I understand, in order to accomplish that I''d have to handle every mouse event and forward it to the appropriate interior control. For each mouse event I''d have to figure out the exact state and location of the mouse, the state and positions of my interior controls (and possibly the controls inside that), see if where the mouse is and it''s state should or should not affect the control it happens to be located over, and then tell that control to respond appropriately. This could get very difficult becaue a MouseMove event on the top level could translate to a MouseMove event, or a MouseHoverEnter event, or a MouseEnter event on a lower level depending on what it happened to be moving over. So it''s not a direct 1-1 correspondance. All because the celltype "Control" won''t just respond to mouse events. Surely there''s an easier way...


AD Administrator Syncfusion Team October 10, 2005 01:21 AM UTC

Hi Tinclon, unfortunately that''s the way it is. Win32 does not provide the necessary tools to forward events nicely from parent to child controls and vice versa. With controls derived from ScrollControl (like the grid control) you can forward events directly to the MouseControllerDispatcher. The MouseControllerDispatcher will then create MouseHover, MouseEnter events on the MouseControllers of the nested grid. TabControl and UserControl are however not derived from ScrollControl so you will have to do a lot of manual work if you want to get hovering working with these controls. If you do only have one instance of the control that you embed into the cell you could try and have the control be a live control and not just a control that gets painted off the screen and then shown as bitmap. You could do such thing by overriding the GridGenericControlCellRenderer.OnDraw method and manully position the tab control on the grid in the cell area. Do not call the base class version of this method. This approach will have however some side effects. The problem is you will not be able to "clip" the contents of the control. If you scroll down and have frozen cells (or just column headers) and only parts of the control visible then it will draw over the frozen area. Win32 does not let you clip a control ... It only supports clipping at edges of the parent control (In a Panel for example you do not have a frozen area and therefore you can scroll child controls out of view and it works there). If you have such a live control you also need to know the grid is not being notified about any clicks inside the child control. The events will go directly to that control. So, if you click from another cell into that control the current cell in the grid will not move. You would have to manually move the current cell onto the cell. Stefan >Okay, here''s my situation. >In one of my cells, I have a Custom Control (Actually a Windows.Forms.UserControl), that itself has Buttons, and a TabControl, and on that TabControl''s pages there are GridControls. These GridControls themselves may have cells with all of the above inside them. > >I need all of these things to be perfectly responsive to all mouse events. > >According to what I understand, in order to accomplish that I''d have to handle every mouse event and forward it to the appropriate interior control. For each mouse event I''d have to figure out the exact state and location of the mouse, the state and positions of my interior controls (and possibly the controls inside that), see if where the mouse is and it''s state should or should not affect the control it happens to be located over, and then tell that control to respond appropriately. > >This could get very difficult becaue a MouseMove event on the top level could translate to a MouseMove event, or a MouseHoverEnter event, or a MouseEnter event on a lower level depending on what it happened to be moving over. So it''s not a direct 1-1 correspondance. > >All because the celltype "Control" won''t just respond to mouse events. > >Surely there''s an easier way... >


CN Clinton Nielsen October 11, 2005 07:01 PM UTC

I made the control a live control as you suggested, and it''s working exactly like I want it to work. Thank you. I solved the problem of the control drawing over the column headers by putting the column headers in a separate GridControl, and having the two GridControls share a scrollbar - so it''s all good there. One problem remains. After having scrolled this "live" control off the screen, and then back on, it won''t repaint. When scrolling the control back onto the screen, all I get is a white empty box where the control should be. How would I go about forcing it to repaint? I tried calling myControl.Refresh() in the custom control renderer, but to no avail. Thanks again.


AD Administrator Syncfusion Team October 11, 2005 08:50 PM UTC

Check and make sure your control has its Visible property set to true when you see this white box, also check its Location to see if it is properly located in this situation.


CN Clinton Nielsen October 11, 2005 10:00 PM UTC

The custom control is both visible, and at the correct location and of the correct size. Everything works fine when scrolling the grid, the problem occurs when the custom control is scrolled out of view and then back into view - for some reason at this point it will no longer paint. Thx.


AD Administrator Syncfusion Team October 12, 2005 02:39 PM UTC

Tinclon, Attached find a sample where I got it working with a LiveCalendarCell. Issues I ran into: - Make sure you call FixControlParent. - Call control.Invalidate from OnDraw - Set control.Bounds in OnDraw vs. setting Location and then Bounds. But most important is the call to FixControlParent. LiveCalendarCells.zip Stefan >The custom control is both visible, and at the correct location and of the correct size. >Everything works fine when scrolling the grid, the problem occurs when the custom control is scrolled out of view and then back into view - for some reason at this point it will no longer paint. > >Thx.


CN Clinton Nielsen October 12, 2005 04:06 PM UTC

Unfortunately, no luck. I had already called FixControlParent, but I tried setting the Bounds instead of the location, then I tried setting the Bounds and the Location. Neither worked. Here''s a small sample that shows kind of what I''m trying to achieve. Try scrolling it around and notice that the custom control in row 20 isn''t refreshing properly. Thanks again!

LiveCell.zip


AD Administrator Syncfusion Team October 12, 2005 04:17 PM UTC

Setting this property in form.Load avoids the refresh I see in your sample. this.gridControl1.DisableScrollWindow = true;


CN Clinton Nielsen October 12, 2005 04:45 PM UTC

Yes, unless another cell is active. Try activating cell A19 and then scrolling. The refresh still isn''t working properly on the Custom Control Cell.


AD Administrator Syncfusion Team October 12, 2005 05:57 PM UTC

There is some blinking, but you can try handling WindowScrolled and refresh the grid there if your bottom row is this custom cell. private void gridControl1_WindowScrolled(object sender, Syncfusion.Windows.Forms.ScrollWindowEventArgs e) { if(this.gridControl1.ViewLayout.LastVisibleRow == 20 && this.gridControl1.ViewLayout.HasPartialVisibleRows) { this.gridControl1.CurrentCell.EndEdit(); this.gridControl1.Refresh(); } }


CN Clinton Nielsen October 12, 2005 06:33 PM UTC

A little better, but now the scrolling is *super* slow, and it still doesn''t work. If the control is scrolled completely off the screen (you''ll probably have to resize the window smaller to do that), then back on, it doesn''t repaint at all. Also, once the two buttons have been scrolled offscreen, they never reappear.


AD Administrator Syncfusion Team October 13, 2005 09:28 PM UTC

Tinclon, it looks like the UserControl somehow caches the coordinates. Only way I found to reset them so that the paint is correct is by calling the Refresh method on the control. Try this code in the LiveCell.zip you uploaded earlier: protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style) { SetControl(CustomControlCellModel.CustomControl); style.Control = CustomControlCellModel.CustomControl; FixControlParent(style.Control); style.Control.Bounds = clientRectangle; style.Control.Refresh(); } Stefan


CN Clinton Nielsen October 14, 2005 02:31 PM UTC

Same problem as before. It works perfectly *unless* another cell has been activated. If I click on a cell other than the "custom control" cell, then scroll, it won''t refresh the custom cell anymore. Thanks.


AD Administrator Syncfusion Team October 14, 2005 02:54 PM UTC

I do not see that problem here. http://www.syncfusion.com/Support/user/uploads/LiveCell_1bd85e35.zip Do you?


CN Clinton Nielsen October 14, 2005 04:33 PM UTC

In that example, the two buttons at the bottom of the Custom Control never appear. Also, if you scroll the window from the very top to the very bottom by grabbing the scrollbar the custom control does not move (it just paints itself exactly where it was even though its corresponding cell has totally changed location)


CN Clinton Nielsen October 14, 2005 08:01 PM UTC

I''ve noticed that the problem I''m experiencing never occurs if the custom control is either fully visible or totally not visible. It only occurs when that row is partially visible and then the screen scrolls. An easy fix (read: workaround) is to just make sure it''s either fully visible, or fully hidden. When the row is near the top and scrolling on and off the top of the form it''s easy to fix by just setting VScrollPixel = false. It gets harder when the row is scrolling on and off the bottom of the form. In this case, it seems to be always partially visible no matter what I do. Could you perhaps tell me how I might change the WindowScrolling or WindowScrolled (or some other applicable event) to ensure that the custom row is either fully on or fully off and never partially visible. I attempted to modify these methods myself, but all of the ScrollWindowEventArgs are readonly, so I can''t modify how much the window is scrolling in the WindowScrolling event. Thanks again.


AD Administrator Syncfusion Team October 17, 2005 11:01 AM UTC

There is some really weird things going on. Either he Button or the Control class has some optimizations that prevent the buttons from drawing once they are out of view. And the only way to get them to draw again is by forcing them manually to reposition them. Here is my try using this approach: LiveCell.zip Stefan


CN Clinton Nielsen October 17, 2005 02:57 PM UTC

I found a solid solution finally!!! Here''s what needs to be in the OnDraw method... protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style) { style.Control = CustomControlCellModel.CustomControl; FixControlParent(style.Control); SetControl(style.Control); style.Control.Bounds = new Rectangle(clientRectangle.X,clientRectangle.Y,clientRectangle.Width-1,clientRectangle.Height-1); style.Control.Refresh(); base.OnDraw(g,clientRectangle,rowIndex,colIndex,style); } Though the scrolling is still a little slower than ideal when the custom control is partially visible, it at least refreshed properly no matter where the focus lies. Thanks again for all your help and ideas! ~Tinclon

Loader.
Live Chat Icon For mobile
Up arrow icon