The Syncfusion® native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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
ADAdministrator Syncfusion Team 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