Home Forums WinForms controls Xceed Grid for WinForms How to hide or remove grid lines

Viewing 1 post (of 1 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17808 |

    There are 2 ways to hide or remove the grid lines: Your first (and easiest) option is to set the GridLineColor and GridLineBackColor properties to Color.Transparent. Your second option is to create a class the derives from the DataCell class and override the Borders property to remove the grid lines completely.

    The following example demonstrates how to hide the grid lines by setting the grid’s GridLineColor and GridLineBackColor properties to Color.Transparent:

    VB.NET

    GridControl1.GridLineColor = Color.Transparent
    GridControl1.GridLineBackColor = Color.Transparent

    C#

    gridControl1.GridLineColor = Color.Transparent;
    gridControl1.GridLineBackColor = Color.Transparent;

    The next example demonstrates how to derive from the DataCell class to override the Borders property and remove the grid lines completely. Keep in mind that you also need to create a class that derives from the DataRow class that will contain your custom cells.

    VB.NET

    Public Class CustomDataCell
      Inherits DataCell

    Protected Sub New ( ByVal template As CustomDataCell )
      MyBase.New( template )
    End Sub

    Public Sub New( ByVal parentColumn As Column )
      MyBase.New( parentColumn )
    End Sub

    Protected Overrides Function CreateInstance() As Cell
      Return New CustomDataCell( Me )
    End Function

    Public Overrides ReadOnly Property Borders As Borders
      Get
        Return Borders.Empty
      End Get
    End Property
    End Class

    Public Class CustomDataRow
      Inherits Xceed.Grid.DataRow

    Public Sub New()
      MyBase.New()
    End Sub

    Protected Sub New( ByVal template As CustomDataRow )
      MyBase.New( template )
    End Sub

    Protected Overrides Function CreateCell( ByVal parentColumn As Column ) As Cell
      Return New CustomDataCell( parentColumn )
    End Function

    Protected Overrides Function CreateInstance() As Row
      Return New CustomDataRow( Me )
    End Function
    End Class

    C#

    public class CustomDataCell : DataCell
    {
      protected CustomDataCell( CustomDataCell template )
        : base( template ){}

      public CustomDataCell( Column parentColumn )
        : base( parentColumn ){}

      protected override Cell CreateInstance()
      {
        return new CustomDataCell( this );
      }

      public override Borders Borders
      {
        get{ return Borders.Empty; }
      }
    }

    public class CustomDataRow : Xceed.Grid.DataRow
    {
      public CustomDataRow()
        : base(){}

      protected CustomDataRow( CustomDataRow template )
        : base( template ){}

      protected override Cell CreateCell( Column parentColumn )
      {
        return new CustomDataCell( parentColumn );
      }

      protected override Row CreateInstance()
      {
        return new CustomDataRow( this );
      }
    }

    In order to use your new DataRow and DataCell, you must assign a new instance of your custom DataRow class to the DataRowTemplate property of the grid:

    VB.NET 

    GridControl1.DataRowTemplate = New CustomDataRow()

    C#

    gridControl1.DataRowTemplate = new CustomDataRow();

    Imported from legacy forums. Posted by Xceed admin (had 1636 views)

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.