ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Task-Based Help / Setting the Grid's Appearance / Placing an Image in a Column Header
In This Topic
    Placing an Image in a Column Header
    In This Topic

    To place an image in a column header, set the ForegroundImage and ForeGroundPicturePosition properties. These properties can be set either in the designer or in code.

    In the Tasks Menu

    To place an image in a column header using the C1TrueDBGrid Tasks menu:

    1. Select the Last column in the grid and click it to open the C1TrueDBGrid Tasks menu.
    2. Select Caption Style from the menu.
    3. Click the Images tab.
    4. Click the ellipsis button next to the Foreground Image. Browse for the image and click Open.
    5. Specify the position of the picture using the Foreground Picture Position drop-down box.
    6. Click Ok to close the Caption Style(Last) dialog box.

    In the C1DisplayColumn Collection Editor

    Alternatively, an image can also be placed in the column header at design time using the C1DisplayColumn Collection Editor.

    1. Click the ellipsis button (...) next to the Splits property of the grid in the Visual Studio Properties window. The Split Collection Editor appears.
    2. Click the ellipsis button next to the DisplayColumns property to bring up the C1DisplayColumn Collection Editor.
    3. Select the column header from the list of Members on the left-hand side.
    4. Expand the HeadingStyle property on the right-hand side.
    5. Click the ellipsis button next to the ForegroundImage property.
    6. Browse for a graphic and click Open.
    7. Specify the position of the graphic using the ForeGroundPicturePosition property.
    8. Click OK to close the C1DisplayColumn Collection Editor.
    9. Click OK again to close the Split Collection Editor.

    In Code

    Add the following code to the Form_Load event:

    1. Specify the image to appear in the header:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Dim bmp As New Bitmap("c:\sort.bmp")
      

      To write code in C#

      C#
      Copy Code
      Bitmap bmp = new Bitmap("c:\\sort.bmp");
      
    2. Specify where the image should appear:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1TrueDBGrid1.Splits(0).DisplayColumns(1).HeadingStyle.ForegroundImage = bmp
      Me.C1TrueDBGrid1.Splits(0).DisplayColumns(1).HeadingStyle.ForeGroundPicturePosition = C1.Win.C1TrueDBGrid.ForeGroundPicturePositionEnum.LeftOfText
      

      To write code in C#

      C#
      Copy Code
      this.c1TrueDBGrid1.Splits[0].DisplayColumns[1].HeadingStyle.ForegroundImage = bmp;
      this.c1TrueDBGrid1.Splits[0].DisplayColumns[1].HeadingStyle.ForeGroundPicturePosition = C1.Win.C1TrueDBGrid.ForeGroundPicturePositionEnum.LeftOfText;
      

    What You've Accomplished

    In this example, the image appears to the left of the text in the header of the Last column: