AD
Administrator
Syncfusion Team
November 6, 2006 07:15 AM UTC
Hi David,
If you want to display images in arbitrary cell types, it probably will be simpler to handle the CellDrawn event, and just draw the image there after the grid has finished doing its default drawing.
Here is a sample that shows how you can use this event to draw images in cells.
http://www.syncfusion.com/Support/user/uploads/GCImageCell_e58d8049.zip
Best Regards,
Haneef
DH
David Hook
November 6, 2006 05:22 PM UTC
Hi Haneef
Thanks for the sample - very useful.
It displays items in a cell as:
Text
Text
Image
How can I change this to show:
Image
Text
Text
In a "static" gridcell?
Thanks in advance.
Best Regards,
David
AD
Administrator
Syncfusion Team
November 7, 2006 04:22 AM UTC
Hi David,
You can achive this by custom drawing the cell in the grid's CellDrawn event handler. Please try the attached sample and let me know if you are trying something different.
Here is a sample.
http://www.syncfusion.com/Support/user/uploads/GCImageCell1_4f3f8f69.zip
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
November 7, 2006 07:12 AM UTC
Hi Andrew,
If you want to draw the focus rectangle in arbitrary cell types, it probably will be simpler to handle the CellDrawn event, and just draw the focusrectanlge there after the grid has finished doing its default drawing. Below is a code snippet
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
if( cc != null
&& cc.RowIndex == e.RowIndex
&& cc.ColIndex == e.ColIndex
&& e.Style.CellType == "MyCellType" )
{
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
e.Cancel = true;
//Draw the focus rctangle Here...
Rectangle rect = e.Bounds;
rect.Inflate(- 5,-5);
rect.Size = new Size(rect.Width -5 ,rect.Height - 5);
e.Graphics.DrawRectangle( Pens.Black,rect);
}
Best Regards,
Haneef
DH
David Hook
November 8, 2006 04:32 PM UTC
Hi Haneef
I think the last reply was for a different thread.
I'm having problems with the resize event - It's not allowing for the image and text in the cell, so I only see the image.
Is there anything I can do about this?
I noticed in your code that you supplied me with that there was the line "this.gridControl1.DefaultRowHeight = 45;".
Hopefully this is not the only way of performing the resize.
Please see attached project for example.
Thanks in advance.
Best Regards,
David
GCImageCell2.zip
AD
Administrator
Syncfusion Team
November 9, 2006 10:25 AM UTC
Hi David,
Sorry for the inconvenience caused.
Issue 1:
If you dont want to resize the row, then you can cancel this operation in the ResizingRows event handler. Kindly try the code below
void gridControl1_ResizingRows(object sender, GridResizingRowsEventArgs e)
{
e.Cancel = true;
}
Issue 2:
To set the row height depends on the cell content, you need to call the Resize to fit method. But it shows only the first line and Image for your application. It doesn't show the Second line. The reason is that you are manually draw Image the cell in a grid. If you want to set the proper height, then you can handle the QueryRowHeight event and set the height of the row in a Grid. Below is a code snippet.
this.grid.QueryRowHeight +=new GridRowColSizeEventHandler(gridQueryColWidth);
private void gridQueryColWidth(object sender, GridRowColSizeEventArgs e)
{
e.Size = 100;
e.Handled = true;
}
Best Regards,
Haneef
DH
David Hook
November 10, 2006 12:38 PM UTC
Hi Haneef
Is there another way of programmatically calculating the height of a drawn cell rather than 'estimating' (or hard coding) the height in code like your example?
e.Size = 100;
Thanks in advance.
Best Regards,
David
AD
Administrator
Syncfusion Team
November 13, 2006 09:17 AM UTC
Hi David,
The sample shows how to automatically resize the grid cells depending on the size of the custom drawing that are placed inside the cells. This can be achieved by overriding a method in the model class called ‘OnQueryPrefferedClientSize’. Through this method, you can return the proper size of the cell. The ResizeToFit() method will then use this method to get the correct size of the custom drawing cell. Please try the attached sample and let me know if this helps.
//Code snippet
protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
{
Size s = base.OnQueryPrefferedClientSize (g, rowIndex, colIndex, style, queryBounds);
s.Height += 17;//Image Height.. of the cell
return s;
}
Sample : http://www.syncfusion.com/Support/user/uploads/CustomResizeTofit_ca1b3509.zip
Best Regards,
Haneef
DH
David Hook
November 14, 2006 03:04 PM UTC
Hi Haneef
Works great! I will now be advising my company to buy in the grid control to use in our software.
Many Thanks for your support,
David