Print Search Rate
    
   11-29-2005, 12:45 PM
HowTo: Placing Multiple Images in a Cell.
Attachment: sgCustomDrawMultipleImages.zip

Many times users want to include multiple images in the same cell. You can achieve this functionality by using an ImageList, the CustomDraw property, and the ImageList_Draw function of SharpGrid. In the approach described below we call the ImageList_Draw function to draw an image list item in the specified device context. In this case each of our image list items will be drawn in the same SharpGrid cell.

Option Explicit Implements IsgGridCustomDraw 'Image list Private Declare Function ImageList_Draw Lib "COMCTL32" (ByVal hImageList As Long, ByVal ImgIndex As Long,_ ByVal hDCDest As Long, ByVal X As Long, ByVal Y As Long, ByVal flags As Long) As Long Private Sub Form_Resize() On Error Resume Next 'Resize sharpGrid SGGrid1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight End Sub Private Sub SGGrid1_OnInit() Dim i As Integer With SGGrid1 Set .PaintObject = Me 'Remove all columns, but the heading column .Columns.RemoveAll False .DataColCount = 1 .DataRowCount = 1 'Set the customdraw property With .Columns(1).Style .TextAlignment = sgAlignRightCenter .CustomDraw = sgDrawAfterCellContent End With 'Place some custom text in the cell .CellAt(1, 1).Value = "Sample Text" 'Set the min height and width for the column so the pictures fit properly .ColWidthMin = 2400 .RowHeightMin = 500 End With End Sub Private Sub IsgGridCustomDraw_DrawCell( _ DrawInfo As sgGridCustomDraw, _ Response As sgCustomDrawResponse) Dim FirstImageIndex, SecondImageIndex, ThirdImageIndex As Long 'Set the image index of the images we want to use from the ImageList FirstImageIndex = 2 SecondImageIndex = 0 ThirdImageIndex = 2 'Draw the pictures in the first cell of the first row If DrawInfo.RowPos = 1 And DrawInfo.ColIndex = 1 Then 'Draw images from the image list ImageList_Draw ImageList1.hImageList, FirstImageIndex, DrawInfo.DC, _ DrawInfo.Left, DrawInfo.Top, 0 ImageList_Draw ImageList1.hImageList, SecondImageIndex, DrawInfo.DC, _ DrawInfo.Left + 20, DrawInfo.Top, 0 ImageList_Draw ImageList1.hImageList, ThirdImageIndex, DrawInfo.DC, _ DrawInfo.Left + 40, DrawInfo.Top, 0 End If End Sub

You can find additional information about the use of the ImageList_Draw function here. The attached sample demonstrates the approach described above.

If you have any questions or need assistance, please feel free to submit a support request.



Applies To:
SharpGrid 2.0
GrapeCity » Knowledge Base » KnowledgeBase f... » HowTo: Placing Multiple Images in a Cell.
Privacy Policy | Copyright © 1997-2012 — GrapeCity, inc.
All trademarks mentioned are the property of their respective owners.