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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Custom Microsoft button in GridControl.

Thread ID:





24381 Feb 2,2005 10:01 PM UTC Feb 3,2005 02:11 PM UTC WinForms 1
Tags: GridControl
Stephen Trinder
Asked On February 2, 2005 10:01 PM UTC

Hi. I''m using the GridControl from version 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\\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 02:11 PM UTC

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


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon