I have a button in a cell. The cell is bigger than the button. The button is positioned on the right side of the cell.
Now that the explanation is down now to the problem. I have tied a cell button click event to the grid which I assume is a very common practice. At runtime if I click on the cell that holds the button (but not clicking on the button itself) it fires the button click event.
Is there any way to suppress this event if the button is not clicked and the cell is?
Thanks,
DVD
AD
Administrator
Syncfusion Team
April 2, 2008 09:59 PM UTC
Hi DVD,
Please refer the below browser sample that demonstrates how to use button edit cells in GridControl and let me know if you need further assistance.
C:\Documents and Settings\{User Name}\My Documents\Syncfusion\EssentialStudio\6.1.0.34\Windows\Grid.Windows\Samples\2.0\CustomCellTypes\ButtonEditCells\cs
Best regards,
Johnson
DV
DVD
April 3, 2008 01:29 PM UTC
Hello Johnson,
I have seen that example but I am just looking at keeping the click event from firing when I have my button to the right. That example has the editor for text which I do not want. My button is aligned correctly, I just don't want the Click event to fire for the button when the mouse is in a part of the cell that does not have the button in it.
Thanks,
DVD
AD
Administrator
Syncfusion Team
April 3, 2008 08:05 PM UTC
Hi DVD,
Thank you for your update.
If your intend to prevent firing of cell click event when you are click PushButton Cell's empty part, you need handle cell
click event and write the code like below
void gridControl1_CellClick(object sender, GridCellClickEventArgs e)
{
GridControl _grid = sender as GridControl;
GridStyleInfo Style = _grid[e.RowIndex, e.ColIndex];
if (Style.CellType == GridCellTypeName.PushButton && cr != null)
{
Rectangle cellBounds = cr.GetCellBoundsCore(e.RowIndex, e.ColIndex);
Point pt = _grid.PointToClient(Control.MousePosition);
if (cellBounds.IntersectsWith(new Rectangle(pt, new Size(1, 1))))
{
if (pt.X < cellBounds.X + Style.BorderMargins.Left)
{
e.Cancel = true;
}
}
}
}
Please Let me know if you need further assistance.
Best regards,
Johnson
DV
DVD
April 8, 2008 07:16 PM UTC
Hello Johnson,
Thank you for the code. The only problem is that it has not yet solved my problem. I have tried digging in to this but I am still having no luck. The cell that has the button has the button aligned to the right. Currently it only occupies one third of the parent cell. Could it have something to do with the way I am drawing my cell in?
public void DrawCellButton(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellButtonEventArgs e)
{
if (e.Style.CellType == "PushButton")
{
int width = 95;
int height = 20;
int Xbounds = ((Syncfusion.Windows.Forms.Grid.GridControl)(sender)).ColWidths[10] - (width + 1);
e.Button.Bounds = Rectangle.FromLTRB(e.Button.Bounds.X + Xbounds, e.Button.Bounds.Y, e.Button.Bounds.X + Xbounds+width, e.Button.Bounds.Y+height);
}
}
Thats how I draw the button to get it aligned to the right.
Thanks,
DVD
JO
Johnson
Syncfusion Team
April 11, 2008 05:16 PM UTC
Hi DVD,
Sorry for the delayed response
The PushButton celltype is designed to occupy the entire size of the grid cell and this is by default. If you dont want the PushButton to occupy the whole
cell and want it centered inside the cell, then set(adjust) the BorderMargins property to specify the size of the pushbutton inside the cell.
Below is the code snippet to have the PushButton centered inside the grid cells.
this.gridGroupingControl1.TableDescriptor.Columns[2].Appearance.AnyRecordFieldCell.CellType = "PushButton";
this.gridGroupingControl1.TableDescriptor.Columns[2].Appearance.AnyRecordFieldCell.Description = "Click!";
this.gridGroupingControl1.TableDescriptor.Columns[2].Appearance.AnyRecordFieldCell.BorderMargins.Left = 40;
this.gridGroupingControl1.TableDescriptor.Columns[2].Appearance.AnyRecordFieldCell.BorderMargins.Right = 0;
Please let me know if you need further assistance.
Best regards,
Johnson