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.

Custom Microsoft button in GridControl.

Thread ID:

Created:

Updated:

Platform:

Replies:

24381 Feb 2,2005 05:01 PM Feb 3,2005 09:11 AM Windows Forms 1
loading
Tags: GridControl
Stephen Trinder
Asked On February 2, 2005 05:01 PM

Hi. I''m using the GridControl from version 3.0.1.0 in VS 2005 (C#). I have a button control that inherits from System.Windows.Forms.Button. It has some features I require for my app. I am trying to get it on the GridControl, and have mostly succeeded. I used the EllipsisCell button from the \Syncfusion\Essential Suite\3.0.1.0\Windows\Grid.Windows\Samples\In Depth\CellButtons sample as a base. I have created a CellModel and a CellRenderer for my button, which works fine, except for 3 problems: I need to call the Init method on my button as the form loads. As I load each row, I do the following: MyGrid.CurrentCell.MoveTo(row, Col); GridCurrentCell cc = MyGrid.CurrentCell; to select the cell I want from the row I''ve just added. Then I cast cc to my custom control: MyButton b = (MyButton)cc.Renderer.Control; Question 1: If I don''t do the MoveTo to select the current cell, cc.Renderer.Control is null. Have I botched something?? Question 2: In my custom button control, in the public class MyButtonCellRenderer : GridGenericControlCellRenderer, I seem to need to create a MyButton (MyButton b = new MyButton();) as a module level variable. If I don''t, back on my form after I cast cc.Renderer.Control to MyButton b, b is null. Question 3: How do I set the text on MyButton? I have tried creating a MyButtonCellButton inheriting from a GridCellButton, and overriding the OnDraw to draw the text, but to no avail. What am I doing wrong? If anyone needs more detail, I can post some more sample code. Thanks! -Stephen

Administrator [Syncfusion]
Replied On February 3, 2005 09:11 AM

Hi Stephen, sample code would be good. Some general info: cc.Renderer.Control will be null if you did not set the Control in your cell type. See the sample Essential Suite\Windows\Grid.Windows\Samples\CellTypes\SliderCells\CS. See SliderCellRenderer and its call to FixControlParent and SetControl. To set text for the MyButton simple set mybutton.Text to the text you want to draw. This can be done before drawing the button, e.g. in your renderers OnDraw method. Let me also add some general notes/background about using GridGenericControlCell: Using GridGenericControlCell will slow down drawing of your grid a bit. The grid does not have much knowledge about the inner workings of such a cell and the integration with the grid is done using some really advanced tips and tricks we found out. Here are two tricks that GridGenericControlCell uses for drawing the cell and forwarding mouse clicks: When drawing the cell it moves the inner control (your button) to a position of the screen (e.g point -1000, -1000). Then it tries to create a snapshot of it. This is done by creating a bitmap and sending WM_PRINT message to the control and force it to print its contents into the bitmap. After that the bitmap is taken and drawn onto the cell area on the grid. Then the bitmap is disposed. After that the original active button is restored. For the active control in order for the cell click to work the grid will position a live control (your button) inside the grid. At the end of the click it will fake a left mouse click using a SendMessage to the control. This works ok but has the disadvantage that the user gets no feedback when he presses the mouse down. At the time you press the mouse down there is only a static bitmap drawn at the position of the cell. The mouse down / mouse up will be handled by the grid (and trigger MouseDown / MouseUp messages etc in the GridCellRendererBase class). Only after the user releases the mouse a active control will be positioned in the cell below the mouse and a mouse click is faked using SendMessage. If you somehow can provide a StaticDraw routine from your underlying Windows Forms Control (the button) you could call that method directly from the cell renderes draw method. That would make things a bit more smooth. Stefan

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.

;