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.
Unfortunately, activation email could not send to your email. Please try again.

Unresponsive Custom Control

Thread ID:

Created:

Updated:

Platform:

Replies:

35448 Sep 29,2005 01:38 PM Oct 17,2005 10:57 AM Windows Forms 21
loading
Tags: GridControl
Clinton Nielsen
Asked On September 29, 2005 01:38 PM

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!

Administrator [Syncfusion]
Replied On September 30, 2005 08:53 AM

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.

Clinton Nielsen
Replied On September 30, 2005 01:42 PM

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.

Administrator [Syncfusion]
Replied On September 30, 2005 11:38 PM

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.

Clinton Nielsen
Replied On October 7, 2005 11:55 AM

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...

Administrator [Syncfusion]
Replied On October 9, 2005 09:21 PM

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... >

Clinton Nielsen
Replied On October 11, 2005 03:01 PM

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.

Administrator [Syncfusion]
Replied On October 11, 2005 04:50 PM

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.

Clinton Nielsen
Replied On October 11, 2005 06:00 PM

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.

Administrator [Syncfusion]
Replied On October 12, 2005 10:39 AM

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.

Clinton Nielsen
Replied On October 12, 2005 12:06 PM

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

Administrator [Syncfusion]
Replied On October 12, 2005 12:17 PM

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

Clinton Nielsen
Replied On October 12, 2005 12:45 PM

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.

Administrator [Syncfusion]
Replied On October 12, 2005 01:57 PM

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

Clinton Nielsen
Replied On October 12, 2005 02:33 PM

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.

Administrator [Syncfusion]
Replied On October 13, 2005 05:28 PM

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

Clinton Nielsen
Replied On October 14, 2005 10:31 AM

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.

Administrator [Syncfusion]
Replied On October 14, 2005 10:54 AM

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

Clinton Nielsen
Replied On October 14, 2005 12:33 PM

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)

Clinton Nielsen
Replied On October 14, 2005 04:01 PM

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.

Administrator [Syncfusion]
Replied On October 17, 2005 07:01 AM

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

Clinton Nielsen
Replied On October 17, 2005 10:57 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;