How to increase the gridview header height when using ColumnGroups

9 posts, 0 answers
  1. Ajay
    Ajay avatar
    29 posts
    Member since:
    Mar 2009

    Posted 19 Mar 2009 Link to this post

    Hi 

    How to increase the gridview header's height when using  ColumnGroups.

    When i am not using the Group header then by following code i am able to increase the size of header by
    following code.

    (this.radGridView1.GridElement as GridTableElement).TableHeaderHeight = 35;

     

     

    but when i am using the group header ,above code is not working or does not have any affect on the header height.
     
    Thanks
    Ajay yadav

     

  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 19 Mar 2009 Link to this post

    Hi Ajay,

    You should set the RowSpan property of some column in this case. Consider the code snippet below:

     
    viewDef.ColumnGroups[1].Rows[0].Columns[0].RowSpan = 40; 
     

    We will add a more convenient API in our upcoming releases.


    Greetings,
    Jack
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kirk Martin
    Kirk Martin avatar
    3 posts
    Member since:
    Oct 2009

    Posted 20 Jan 2010 Link to this post

    I am using Q3 2009 SP1 version of this control.  I have a grid with several columngroups and several group rows (three to be factual).  I have tried the code you suggested and it had no effect.  Should I be setting the rowspan for the first column for each group row ?

    I am attempting to rotate the text to a vertical orientation within the group to be able to display the full text while displaying multiple columns.  Below is the code; (sorry it includes stuff I put in just for testing)

    Imports Telerik.WinControls
    Imports Telerik.WinControls.UI

    Public Class frmTesting

        Private tableview As TableViewDefinition
        Private columngroupview As ColumnGroupsViewDefinition


        Private Sub frmTesting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            CreateGridColumns()
            tableview = TryCast(RadGridView1.ViewDefinition, TableViewDefinition)
            InitGrid()

        End Sub
        Private Sub GridReset()

            RadGridView1.ViewDefinition = tableview
            CreateGridColumns()
            'tableview = TryCast(RadGridView1.ViewDefinition, TableViewDefinition)
            InitGrid()

            If OptViewTable.ToggleState = Enumerations.ToggleState.On Then

                RadGridView1.ViewDefinition = Me.tableview
            Else
                RadGridView1.ViewDefinition = Me.columngroupview

            End If

            'RadGridView1.ViewDefinition = IIf(optViewCol.ToggleState = Enumerations.ToggleState.On, columngroupview, tableview)

        End Sub
        Private Sub InitGrid()


            Me.columngroupview = New ColumnGroupsViewDefinition

            Me.columngroupview.ColumnGroups.Add(New GridViewColumnGroup("General"))
            Me.columngroupview.ColumnGroups.Add(New GridViewColumnGroup("Mathematics"))
            Me.columngroupview.ColumnGroups.Add(New GridViewColumnGroup("Language"))
            Me.columngroupview.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Homework 1"))
            Me.columngroupview.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Mid term 1"))
            Me.columngroupview.ColumnGroups(2).Groups.Add(New GridViewColumnGroup("Classwork 1"))
            Me.columngroupview.ColumnGroups(2).Groups.Add(New GridViewColumnGroup("Finals"))


            Me.columngroupview.ColumnGroups(0).Rows.Add(New GridViewColumnGroupRow())
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(0))
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(1))
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(2))
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(3))
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(4))


            If RadRadioButton2.ToggleState = Enumerations.ToggleState.On Then


                Me.columngroupview.ColumnGroups(1).Groups(0).Rows.Add(New GridViewColumnGroupRow())
                Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(5))
                Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(6))
                Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(7))
                Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(8))

                Me.columngroupview.ColumnGroups(1).Groups(1).Rows.Add(New GridViewColumnGroupRow())
                Me.columngroupview.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(9))
                Me.columngroupview.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(10))
                Me.columngroupview.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(11))
                Me.columngroupview.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(12))



                Me.columngroupview.ColumnGroups(2).Groups(0).Rows.Add(New GridViewColumnGroupRow())
                Me.columngroupview.ColumnGroups(2).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(13))
                Me.columngroupview.ColumnGroups(2).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(14))
                Me.columngroupview.ColumnGroups(2).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(15))
                Me.columngroupview.ColumnGroups(2).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(16))

                Me.columngroupview.ColumnGroups(2).Groups(1).Rows.Add(New GridViewColumnGroupRow())
                Me.columngroupview.ColumnGroups(2).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(17))
                Me.columngroupview.ColumnGroups(2).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(18))
                Me.columngroupview.ColumnGroups(2).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(19))
                Me.columngroupview.ColumnGroups(2).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(20))

            End If

            'Me.columngroupview.ColumnGroups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(9))
            'Me.columngroupview.ColumnGroups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(10))
            'Me.columngroupview.ColumnGroups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(11))

        End Sub

        Private Sub OptViewTable_ToggleStateChanged(ByVal sender As System.Object, ByVal args As Telerik.WinControls.UI.StateChangedEventArgs) Handles OptViewTable.ToggleStateChanged, optViewCol.ToggleStateChanged

            Dim Seloption As RadRadioButton

            Seloption = TryCast(sender, RadRadioButton)

            If Seloption.ToggleState = Enumerations.ToggleState.On Then

                If Seloption.Name = "OptViewTable" Then

                    Me.RadGridView1.ViewDefinition = tableview
                    Me.RadGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
                    'RadGroupBox1.Enabled = False

                Else
                    Me.RadGridView1.ViewDefinition = columngroupview
                    Me.RadGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None
                    'RadGroupBox1.Enabled = True
                End If

            End If

        End Sub
        Private Sub CreateGridColumns()

            Dim RowtoAdd As GridViewRowInfo

            'Will try to load some Columns here
            With RadGridView1

                If .Rows.Count > 0 Then .Rows.Clear()

                .Columns.Clear()
                .Columns.Add(New GridViewDecimalColumn("Student_ID"))
                .Columns("Student_ID").IsVisible = False
                .Columns.Add(New GridViewTextBoxColumn("Student_Code"))
                .Columns("Student_Code").HeaderText = "Student Code"
                .Columns.Add(New GridViewTextBoxColumn("Surname"))
                .Columns.Add(New GridViewTextBoxColumn("First_Name"))
                .Columns("First_Name").HeaderText = "First Name"
                .Columns.Add(New GridViewTextBoxColumn("Other_Names"))
                .Columns("Other_Names").HeaderText = "Other Names"

                If RadRadioButton2.ToggleState = Enumerations.ToggleState.On Then

                    'Subject 1 paper 1 and 2
                    .Columns.Add(New GridViewDecimalColumn("S1P1Raw"))
                    .Columns("S1P1Raw").HeaderText = "Raw"
                    .Columns.Add(New GridViewDecimalColumn("S1P1Percent"))
                    .Columns("S1P1Percent").HeaderText = "Percent"
                    .Columns.Add(New GridViewDecimalColumn("S1P1Std"))
                    .Columns("S1P1Std").HeaderText = "Std. Score"
                    .Columns.Add(New GridViewTextBoxColumn("S1P1Att"))
                    .Columns("S1P1Att").HeaderText = "Attendance"
                    .Columns.Add(New GridViewDecimalColumn("S1P2Raw"))
                    .Columns("S1P2Raw").HeaderText = "Raw"
                    .Columns.Add(New GridViewDecimalColumn("S1P2Percent"))
                    .Columns("S1P2Percent").HeaderText = "Percent"
                    .Columns.Add(New GridViewDecimalColumn("S1P2Std"))
                    .Columns("S1P2Std").HeaderText = "Std. Score"
                    .Columns.Add(New GridViewTextBoxColumn("S1P2Att"))
                    .Columns("S1P2Att").HeaderText = "Attendance"

                    'Subject 2 Papers 1 and 2

                    .Columns.Add(New GridViewDecimalColumn("S2P1Raw"))
                    .Columns("S2P1Raw").HeaderText = "Raw"
                    .Columns.Add(New GridViewDecimalColumn("S2P1Percent"))
                    .Columns("S2P1Percent").HeaderText = "Percent"
                    .Columns.Add(New GridViewDecimalColumn("S2P1Std"))
                    .Columns("S2P1Std").HeaderText = "Std. Score"
                    .Columns.Add(New GridViewTextBoxColumn("S2P1Att"))
                    .Columns("S2P1Att").HeaderText = "Attendance"
                    .Columns.Add(New GridViewDecimalColumn("S2P2Raw"))
                    .Columns("S2P2Raw").HeaderText = "Raw"
                    .Columns.Add(New GridViewDecimalColumn("S2P2Percent"))
                    .Columns("S2P2Percent").HeaderText = "Percent"
                    .Columns.Add(New GridViewDecimalColumn("S2P2Std"))
                    .Columns("S2P2Std").HeaderText = "Std. Score"
                    .Columns.Add(New GridViewTextBoxColumn("S2P2Att"))
                    .Columns("S2P2Att").HeaderText = "Attendance"


                    RowtoAdd = .Rows.AddNew()

                    With RowtoAdd

                        .Cells(0).Value = 1228
                        .Cells(1).Value = "09837AD28"
                        .Cells(2).Value = "Da'Vid"
                        .Cells(3).Value = "Ziva"
                        .Cells(4).Value = "Go bathe"
                        .Cells(5).Value = 85
                        .Cells(6).Value = 0.75
                        .Cells(7).Value = 315
                        .Cells(8).Value = "Present"
                        .Cells(9).Value = 0
                        .Cells(10).Value = 0
                        .Cells(11).Value = 0
                        .Cells(12).Value = "Excused"
                        .Cells(13).Value = vbNullString
                        .Cells(14).Value = vbNullString
                        .Cells(15).Value = vbNullString
                        .Cells(16).Value = vbNullString
                        .Cells(17).Value = 68
                        .Cells(18).Value = 0.8359
                        .Cells(19).Value = 345
                        .Cells(20).Value = "Present"
                        '.Height = 20

                    End With
                    RowtoAdd = .Rows.AddNew()

                    With RowtoAdd

                        .Cells(0).Value = 1924
                        .Cells(1).Value = "00088402"
                        .Cells(2).Value = "Berry"
                        .Cells(3).Value = "Haley"
                        .Cells(4).Value = "Marie"
                        .Cells(5).Value = 58
                        .Cells(6).Value = 0.78
                        .Cells(7).Value = 234
                        .Cells(8).Value = "Present"
                        .Cells(9).Value = 57
                        .Cells(10).Value = 0.33
                        .Cells(11).Value = 287
                        .Cells(12).Value = "Present"
                        .Cells(13).Value = 0
                        .Cells(14).Value = 0
                        .Cells(15).Value = 0
                        .Cells(16).Value = "Absent"
                        .Cells(17).Value = 73
                        .Cells(18).Value = 0.57
                        .Cells(19).Value = 332
                        .Cells(20).Value = "Present"
                        '.Height = 20

                    End With

                    RowtoAdd = .Rows.AddNew()

                    With RowtoAdd

                        .Cells(0).Value = 234
                        .Cells(1).Value = "335DG257"
                        .Cells(2).Value = "Stephens"
                        .Cells(3).Value = "Joseph"
                        .Cells(4).Value = "Michael"
                        .Cells(5).Value = 0
                        .Cells(6).Value = 0
                        .Cells(7).Value = 0
                        .Cells(8).Value = "Present"
                        .Cells(9).Value = 50
                        .Cells(10).Value = 0.235
                        .Cells(11).Value = 118
                        .Cells(12).Value = "Present"
                        .Cells(13).Value = 98
                        .Cells(14).Value = 0.8924
                        .Cells(15).Value = 321
                        .Cells(16).Value = "Present"
                        .Cells(17).Value = 0
                        .Cells(18).Value = 0
                        .Cells(19).Value = 0
                        .Cells(20).Value = vbNullString
                        '.Height = 20

                    End With

                End If

            End With

        End Sub

        Private Sub RadGridView1_CurrentColumnChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CurrentColumnChangedEventArgs) Handles RadGridView1.CurrentColumnChanged

        End Sub

        Private Sub RadRadioButton1_ToggleStateChanged(ByVal sender As Object, ByVal args As Telerik.WinControls.UI.StateChangedEventArgs) Handles RadRadioButton1.ToggleStateChanged
            GridReset()
        End Sub

        Private Sub RadGridView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadGridView1.Click

        End Sub

        Private Sub RadGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RadGridView1.MouseClick

            Dim pointedat As RadElement, groupHead As GridColumnGroupCellElement

            'MsgBox(sender.ToString)
            pointedat = Me.RadGridView1.ElementTree.GetElementAtPoint(e.Location)
            'MsgBox(pointedat.RadObjectType.Name.ToString)

            If TypeOf pointedat Is GridColumnGroupCellElement Then

                groupHead = TryCast(pointedat, GridColumnGroupCellElement)
                MsgBox(groupHead.Text)

            End If

        End Sub

        Private Sub RadGridView1_ViewCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting

            If TypeOf e.CellElement Is GridColumnGroupCellElement Then

                Dim mFont As New Font(SystemFonts.DialogFont, FontStyle.Bold)
                e.CellElement.Font = mFont

            ElseIf TypeOf e.CellElement Is GridHeaderCellElement Then

                If e.CellElement.ColumnIndex > 4 Then

                    e.CellElement.TextOrientation = Orientation.Vertical

                End If


            End If

        End Sub

    End Class
  5. JigneshGN
    JigneshGN avatar
    10 posts
    Member since:
    May 2009

    Posted 22 Jan 2010 Link to this post

    Hi Jack,

    I have same problem, when I tried to set rowspan property I found there is not effect for changing rowspan property.

    Is there any requirement for setting rowspan property.

    Please help.

    Regards,
    Jignesh Patel
  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 25 Jan 2010 Link to this post

    Hi Kirk,

    I looked at your code and I cannot find the line where you are setting the RowSpan property. Please, send me your application and specify the result that you expect. I will try to find a solution.

    Jignesh, could you please give more details on this issue. I admit, that this property name may be a little confusing. Actually, we support row span feature only in HTML view mode. When using column groups view, this property specifies the row height.

    All the best,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. JigneshGN
    JigneshGN avatar
    10 posts
    Member since:
    May 2009

    Posted 25 Jan 2010 Link to this post

    Hi Jack,

    Thank you for your reply.

    If it is possible in HTML view only then it will not solve my problem because I have used column groups view.

    Thank you.
  8. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 26 Jan 2010 Link to this post

    Hi Jignesh,

    In this case I would suggest using HTML view. You can find an example in our demo application. The following blog article is also a good starting point.

    Greetings,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Kirk Martin
    Kirk Martin avatar
    3 posts
    Member since:
    Oct 2009

    Posted 26 Jan 2010 Link to this post

    Thanks Jack.  Sorry about not including the line.  This was a form I was using to test the functionality, so I had removed it before posting.  My apologies. 
    That said, I had continued experimenting with it, and realized that I was placing the code in the wrong event.  I have since corrected it and I now have the form working.

    Thanks much for your help...

    Here is the code... if anyone else is interested... (incidentally... it's very commented...)

    the Form designer....
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class frmTesting
        Inherits System.Windows.Forms.Form

        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Dim GridSortField1 As Telerik.WinControls.UI.GridSortField = New Telerik.WinControls.UI.GridSortField
            Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView
            Me.OptViewTable = New Telerik.WinControls.UI.RadRadioButton
            Me.optViewCol = New Telerik.WinControls.UI.RadRadioButton
            Me.RadGroupBox1 = New Telerik.WinControls.UI.RadGroupBox
            Me.RadRadioButton2 = New Telerik.WinControls.UI.RadRadioButton
            Me.RadRadioButton1 = New Telerik.WinControls.UI.RadRadioButton
            CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadGridView1.MasterGridViewTemplate, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.OptViewTable, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.optViewCol, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadGroupBox1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.RadGroupBox1.SuspendLayout()
            CType(Me.RadRadioButton2, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadRadioButton1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'RadGridView1
            '
            Me.RadGridView1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.RadGridView1.BackColor = System.Drawing.SystemColors.Control
            Me.RadGridView1.Cursor = System.Windows.Forms.Cursors.Default
            Me.RadGridView1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
            Me.RadGridView1.ForeColor = System.Drawing.SystemColors.ControlText
            Me.RadGridView1.ImeMode = System.Windows.Forms.ImeMode.NoControl
            Me.RadGridView1.Location = New System.Drawing.Point(12, 85)
            '
            '
            '
            Me.RadGridView1.MasterGridViewTemplate.AllowAddNewRow = False
            Me.RadGridView1.MasterGridViewTemplate.AutoExpandGroups = True
            Me.RadGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
            GridSortField1.FieldAlias = "DateOfBirth"
            GridSortField1.FieldName = "DateOfBirth"
            GridSortField1.SortOrder = Telerik.WinControls.UI.RadSortOrder.Ascending
            Me.RadGridView1.MasterGridViewTemplate.SortExpressions.Add(GridSortField1)
            Me.RadGridView1.Name = "RadGridView1"
            Me.RadGridView1.ReadOnly = True
            Me.RadGridView1.RightToLeft = System.Windows.Forms.RightToLeft.No
            Me.RadGridView1.ShowGroupPanel = False
            Me.RadGridView1.Size = New System.Drawing.Size(768, 381)
            Me.RadGridView1.TabIndex = 0
            '
            'OptViewTable
            '
            Me.OptViewTable.Location = New System.Drawing.Point(29, 47)
            Me.OptViewTable.Name = "OptViewTable"
            Me.OptViewTable.Size = New System.Drawing.Size(104, 15)
            Me.OptViewTable.TabIndex = 1
            Me.OptViewTable.Text = "StandardView"
            Me.OptViewTable.ToggleState = Telerik.WinControls.Enumerations.ToggleState.[On]
            '
            'optViewCol
            '
            Me.optViewCol.Location = New System.Drawing.Point(170, 47)
            Me.optViewCol.Name = "optViewCol"
            Me.optViewCol.Size = New System.Drawing.Size(160, 15)
            Me.optViewCol.TabIndex = 2
            Me.optViewCol.Text = "ColumnGroupView"
            '
            'RadGroupBox1
            '
            Me.RadGroupBox1.Controls.Add(Me.RadRadioButton2)
            Me.RadGroupBox1.Controls.Add(Me.RadRadioButton1)
            Me.RadGroupBox1.FooterImageIndex = -1
            Me.RadGroupBox1.FooterImageKey = ""
            Me.RadGroupBox1.HeaderImageIndex = -1
            Me.RadGroupBox1.HeaderImageKey = ""
            Me.RadGroupBox1.HeaderMargin = New System.Windows.Forms.Padding(0)
            Me.RadGroupBox1.HeaderText = ""
            Me.RadGroupBox1.Location = New System.Drawing.Point(343, 37)
            Me.RadGroupBox1.Name = "RadGroupBox1"
            Me.RadGroupBox1.Padding = New System.Windows.Forms.Padding(10, 20, 10, 10)
            Me.RadGroupBox1.Size = New System.Drawing.Size(318, 33)
            Me.RadGroupBox1.TabIndex = 3
            '
            'RadRadioButton2
            '
            Me.RadRadioButton2.BackColor = System.Drawing.Color.Transparent
            Me.RadRadioButton2.Location = New System.Drawing.Point(159, 7)
            Me.RadRadioButton2.Name = "RadRadioButton2"
            Me.RadRadioButton2.Size = New System.Drawing.Size(126, 17)
            Me.RadRadioButton2.TabIndex = 1
            Me.RadRadioButton2.Text = "with data"
            '
            'RadRadioButton1
            '
            Me.RadRadioButton1.BackColor = System.Drawing.Color.Transparent
            Me.RadRadioButton1.Location = New System.Drawing.Point(21, 7)
            Me.RadRadioButton1.Name = "RadRadioButton1"
            Me.RadRadioButton1.Size = New System.Drawing.Size(93, 17)
            Me.RadRadioButton1.TabIndex = 0
            Me.RadRadioButton1.Text = "no data"
            Me.RadRadioButton1.ToggleState = Telerik.WinControls.Enumerations.ToggleState.[On]
            '
            'frmTesting
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(792, 475)
            Me.Controls.Add(Me.RadGroupBox1)
            Me.Controls.Add(Me.optViewCol)
            Me.Controls.Add(Me.OptViewTable)
            Me.Controls.Add(Me.RadGridView1)
            Me.Name = "frmTesting"
            Me.Text = "frmTesting"
            CType(Me.RadGridView1.MasterGridViewTemplate, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.OptViewTable, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.optViewCol, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadGroupBox1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.RadGroupBox1.ResumeLayout(False)
            CType(Me.RadRadioButton2, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadRadioButton1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub
        Friend WithEvents RadGridView1 As Telerik.WinControls.UI.RadGridView
        Friend WithEvents OptViewTable As Telerik.WinControls.UI.RadRadioButton
        Friend WithEvents optViewCol As Telerik.WinControls.UI.RadRadioButton
        Friend WithEvents RadGroupBox1 As Telerik.WinControls.UI.RadGroupBox
        Friend WithEvents RadRadioButton2 As Telerik.WinControls.UI.RadRadioButton
        Friend WithEvents RadRadioButton1 As Telerik.WinControls.UI.RadRadioButton
    End Class

    The form Code itself ...

    Imports Telerik.WinControls
    Imports Telerik.WinControls.UI


    Public Class frmTesting

        Private tableview As TableViewDefinition
        Private columngroupview As ColumnGroupsViewDefinition


        Private Sub frmTesting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


            CreateGridColumns()
            tableview = TryCast(RadGridView1.ViewDefinition, TableViewDefinition)
            InitGrid()


        End Sub
        Private Sub GridReset()

            RadGridView1.ViewDefinition = tableview
            CreateGridColumns()
            'tableview = TryCast(RadGridView1.ViewDefinition, TableViewDefinition)
            InitGrid()

            If OptViewTable.ToggleState = Enumerations.ToggleState.On Then

                RadGridView1.ViewDefinition = Me.tableview

                RadGridView1.GridElement.TableHeaderHeight = 90

            Else

                RadGridView1.ViewDefinition = Me.columngroupview
                Me.RadGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None

                If Me.columngroupview.ColumnGroups(1).Groups(0).Rows.Count > 0 Then
                    Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns(0).RowSpan = 90
                    For Each Row As GridViewDataRowInfo In Me.RadGridView1.Rows
                        Row.Height = 30
                    Next
                End If

            End If

            'RadGridView1.ViewDefinition = IIf(optViewCol.ToggleState = Enumerations.ToggleState.On, columngroupview, tableview)

        End Sub
        Private Sub InitGrid()


            Me.columngroupview = New ColumnGroupsViewDefinition

            Me.columngroupview.ColumnGroups.Add(New GridViewColumnGroup("General"))
            'Me.columngroupview.ColumnGroups.Add(New GridViewColumnGroup("Mathematics"))
            'Me.columngroupview.ColumnGroups.Add(New GridViewColumnGroup("Language"))
            Me.columngroupview.ColumnGroups.Add(New GridViewColumnGroup("S1"))
            Me.columngroupview.ColumnGroups.Add(New GridViewColumnGroup("S2"))

            'Me.columngroupview.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Homework 1"))
            'Me.columngroupview.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Mid term 1"))
            'Me.columngroupview.ColumnGroups(2).Groups.Add(New GridViewColumnGroup("Classwork 1"))
            'Me.columngroupview.ColumnGroups(2).Groups.Add(New GridViewColumnGroup("Finals"))

            Me.columngroupview.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("S1P1"))
            Me.columngroupview.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("S1P2"))
            Me.columngroupview.ColumnGroups(2).Groups.Add(New GridViewColumnGroup("S2P1"))
            Me.columngroupview.ColumnGroups(2).Groups.Add(New GridViewColumnGroup("S2P2"))

            Me.columngroupview.ColumnGroups(0).Rows.Add(New GridViewColumnGroupRow())
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(0))
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(1))
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(2))
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(3))
            Me.columngroupview.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(4))


            If RadRadioButton2.ToggleState = Enumerations.ToggleState.On Then


                Me.columngroupview.ColumnGroups(1).Groups(0).Rows.Add(New GridViewColumnGroupRow())
                Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(5))
                Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(6))
                Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(7))
                Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(8))

                Me.columngroupview.ColumnGroups(1).Groups(1).Rows.Add(New GridViewColumnGroupRow())
                Me.columngroupview.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(9))
                Me.columngroupview.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(10))
                Me.columngroupview.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(11))
                Me.columngroupview.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(12))



                Me.columngroupview.ColumnGroups(2).Groups(0).Rows.Add(New GridViewColumnGroupRow())
                Me.columngroupview.ColumnGroups(2).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(13))
                Me.columngroupview.ColumnGroups(2).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(14))
                Me.columngroupview.ColumnGroups(2).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(15))
                Me.columngroupview.ColumnGroups(2).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns(16))

                Me.columngroupview.ColumnGroups(2).Groups(1).Rows.Add(New GridViewColumnGroupRow())
                Me.columngroupview.ColumnGroups(2).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(17))
                Me.columngroupview.ColumnGroups(2).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(18))
                Me.columngroupview.ColumnGroups(2).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(19))
                Me.columngroupview.ColumnGroups(2).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(20))


            End If

            'Me.columngroupview.ColumnGroups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(9))
            'Me.columngroupview.ColumnGroups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(10))
            'Me.columngroupview.ColumnGroups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns(11))

        End Sub

        Private Sub OptViewTable_ToggleStateChanged(ByVal sender As System.Object, ByVal args As Telerik.WinControls.UI.StateChangedEventArgs) Handles OptViewTable.ToggleStateChanged, optViewCol.ToggleStateChanged

            Dim Seloption As RadRadioButton

            Seloption = TryCast(sender, RadRadioButton)

            If Seloption.ToggleState = Enumerations.ToggleState.On Then

                If Seloption.Name = "OptViewTable" Then

                    Me.RadGridView1.ViewDefinition = tableview
                    Me.RadGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
                    'RadGroupBox1.Enabled = False
                    RadGridView1.GridElement.TableHeaderHeight = 90


                Else

                    Me.RadGridView1.ViewDefinition = columngroupview
                    Me.RadGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None

                    If Me.columngroupview.ColumnGroups(1).Groups(0).Rows.Count > 0 Then
                        Me.columngroupview.ColumnGroups(1).Groups(0).Rows(0).Columns(0).RowSpan = 90
                        For Each Row As GridViewDataRowInfo In Me.RadGridView1.Rows
                            Row.Height = 30
                        Next
                    End If
                End If

            End If

        End Sub
        Private Sub CreateGridColumns()

            Dim RowtoAdd As GridViewRowInfo

            'Will try to load some Columns here
            With RadGridView1

                If .Rows.Count > 0 Then .Rows.Clear()

                .Columns.Clear()
                .Columns.Add(New GridViewDecimalColumn("Student_ID"))
                .Columns("Student_ID").IsVisible = False
                .Columns.Add(New GridViewTextBoxColumn("Student_Code"))
                .Columns("Student_Code").HeaderText = "Student Code"
                .Columns.Add(New GridViewTextBoxColumn("Surname"))
                .Columns.Add(New GridViewTextBoxColumn("First_Name"))
                .Columns("First_Name").HeaderText = "First Name"
                .Columns.Add(New GridViewTextBoxColumn("Other_Names"))
                .Columns("Other_Names").HeaderText = "Other Names"

                If RadRadioButton2.ToggleState = Enumerations.ToggleState.On Then

                    'Subject 1 paper 1 and 2
                    .Columns.Add(New GridViewDecimalColumn("S1P1Raw"))
                    .Columns("S1P1Raw").HeaderText = "Raw"
                    .Columns.Add(New GridViewDecimalColumn("S1P1Percent"))
                    .Columns("S1P1Percent").HeaderText = "Percent"
                    .Columns.Add(New GridViewDecimalColumn("S1P1Std"))
                    .Columns("S1P1Std").HeaderText = "Std. Score"
                    .Columns.Add(New GridViewTextBoxColumn("S1P1Att"))
                    .Columns("S1P1Att").HeaderText = "Attendance"
                    .Columns.Add(New GridViewDecimalColumn("S1P2Raw"))
                    .Columns("S1P2Raw").HeaderText = "Raw"
                    .Columns.Add(New GridViewDecimalColumn("S1P2Percent"))
                    .Columns("S1P2Percent").HeaderText = "Percent"
                    .Columns.Add(New GridViewDecimalColumn("S1P2Std"))
                    .Columns("S1P2Std").HeaderText = "Std. Score"
                    .Columns.Add(New GridViewTextBoxColumn("S1P2Att"))
                    .Columns("S1P2Att").HeaderText = "Attendance"

                    'Subject 2 Papers 1 and 2

                    .Columns.Add(New GridViewDecimalColumn("S2P1Raw"))
                    .Columns("S2P1Raw").HeaderText = "Raw"
                    .Columns.Add(New GridViewDecimalColumn("S2P1Percent"))
                    .Columns("S2P1Percent").HeaderText = "Percent"
                    .Columns.Add(New GridViewDecimalColumn("S2P1Std"))
                    .Columns("S2P1Std").HeaderText = "Std. Score"
                    .Columns.Add(New GridViewTextBoxColumn("S2P1Att"))
                    .Columns("S2P1Att").HeaderText = "Attendance"
                    .Columns.Add(New GridViewDecimalColumn("S2P2Raw"))
                    .Columns("S2P2Raw").HeaderText = "Raw"
                    .Columns.Add(New GridViewDecimalColumn("S2P2Percent"))
                    .Columns("S2P2Percent").HeaderText = "Percent"
                    .Columns.Add(New GridViewDecimalColumn("S2P2Std"))
                    .Columns("S2P2Std").HeaderText = "Std. Score"
                    .Columns.Add(New GridViewTextBoxColumn("S2P2Att"))
                    .Columns("S2P2Att").HeaderText = "Attendance"


                    RowtoAdd = .Rows.AddNew()

                    With RowtoAdd

                        .Cells(0).Value = 1228
                        .Cells(1).Value = "09837AD28"
                        .Cells(2).Value = "Da'Vid"
                        .Cells(3).Value = "Ziva"
                        .Cells(4).Value = "Go bathe"
                        .Cells(5).Value = 85
                        .Cells(6).Value = 0.75
                        .Cells(7).Value = 315
                        .Cells(8).Value = "Present"
                        .Cells(9).Value = 0
                        .Cells(10).Value = 0
                        .Cells(11).Value = 0
                        .Cells(12).Value = "Excused"
                        .Cells(13).Value = vbNullString
                        .Cells(14).Value = vbNullString
                        .Cells(15).Value = vbNullString
                        .Cells(16).Value = vbNullString
                        .Cells(17).Value = 68
                        .Cells(18).Value = 0.8359
                        .Cells(19).Value = 345
                        .Cells(20).Value = "Present"
                        '.Height = 20

                    End With
                    RowtoAdd = .Rows.AddNew()

                    With RowtoAdd

                        .Cells(0).Value = 1924
                        .Cells(1).Value = "00088402"
                        .Cells(2).Value = "Berry"
                        .Cells(3).Value = "Haley"
                        .Cells(4).Value = "Marie"
                        .Cells(5).Value = 58
                        .Cells(6).Value = 0.78
                        .Cells(7).Value = 234
                        .Cells(8).Value = "Present"
                        .Cells(9).Value = 57
                        .Cells(10).Value = 0.33
                        .Cells(11).Value = 287
                        .Cells(12).Value = "Present"
                        .Cells(13).Value = 0
                        .Cells(14).Value = 0
                        .Cells(15).Value = 0
                        .Cells(16).Value = "Absent"
                        .Cells(17).Value = 73
                        .Cells(18).Value = 0.57
                        .Cells(19).Value = 332
                        .Cells(20).Value = "Present"
                        '.Height = 20

                    End With

                    RowtoAdd = .Rows.AddNew()

                    With RowtoAdd

                        .Cells(0).Value = 234
                        .Cells(1).Value = "335DG257"
                        .Cells(2).Value = "Stephens"
                        .Cells(3).Value = "Joseph"
                        .Cells(4).Value = "Michael"
                        .Cells(5).Value = 0
                        .Cells(6).Value = 0
                        .Cells(7).Value = 0
                        .Cells(8).Value = "Present"
                        .Cells(9).Value = 50
                        .Cells(10).Value = 0.235
                        .Cells(11).Value = 118
                        .Cells(12).Value = "Present"
                        .Cells(13).Value = 98
                        .Cells(14).Value = 0.8924
                        .Cells(15).Value = 321
                        .Cells(16).Value = "Present"
                        .Cells(17).Value = 0
                        .Cells(18).Value = 0
                        .Cells(19).Value = 0
                        .Cells(20).Value = vbNullString
                        '.Height = 20

                    End With

                End If

            End With

        End Sub

        Private Sub RadGridView1_CellClick(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellClick


        End Sub

        Private Sub RadGridView1_CurrentColumnChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CurrentColumnChangedEventArgs) Handles RadGridView1.CurrentColumnChanged

        End Sub

        Private Sub RadRadioButton1_ToggleStateChanged(ByVal sender As Object, ByVal args As Telerik.WinControls.UI.StateChangedEventArgs) Handles RadRadioButton1.ToggleStateChanged
            GridReset()
        End Sub

        Private Sub RadGridView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadGridView1.Click

        End Sub

        Private Sub RadGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RadGridView1.MouseClick

            Dim pointedat As RadElement, groupHead As GridColumnGroupCellElement

            'MsgBox(sender.ToString)
            pointedat = Me.RadGridView1.ElementTree.GetElementAtPoint(e.Location)
            'MsgBox(pointedat.RadObjectType.Name.ToString)

            If TypeOf pointedat Is GridColumnGroupCellElement Then

                groupHead = TryCast(pointedat, GridColumnGroupCellElement)

                If Not groupHead.Tag Is Nothing Then

                    MsgBox(groupHead.Tag.ToString)

                End If

            End If
        End Sub

        Private Sub RadGridView1_ViewCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting

            Dim strCT As String, strTag As String

            If TypeOf e.CellElement Is GridColumnGroupCellElement Then


                strCT = e.CellElement.Text

                Select Case strCT

                    Case "S1"
                        e.CellElement.Text = "Mathematics"
                        strTag = strCT
                        e.CellElement.Tag = strCT
                    Case "S2"
                        e.CellElement.Text = "Language"
                        strTag = strCT
                        e.CellElement.Tag = strCT
                    Case "S1P1"
                        e.CellElement.Text = "Homework"
                        strTag = strCT
                        e.CellElement.Tag = strCT
                    Case "S1P2"
                        e.CellElement.Text = "Mid-Term Test"
                        strTag = strCT
                        e.CellElement.Tag = strCT
                    Case "S2P1"
                        e.CellElement.Text = "Vocabulary Test"
                        strTag = strCT
                        e.CellElement.Tag = strCT
                    Case "S2P2"
                        e.CellElement.Text = "Composition HW"
                        strTag = strCT
                        e.CellElement.Tag = strCT

                End Select

                Dim mFont As New Font(SystemFonts.DialogFont, FontStyle.Bold)
                e.CellElement.Font = mFont
                e.CellElement.TextAlignment = ContentAlignment.MiddleCenter

            ElseIf TypeOf e.CellElement Is GridHeaderCellElement Then

                If e.CellElement.ColumnIndex > 4 Then

                    e.CellElement.TextOrientation = Orientation.Vertical

                End If


            End If

        End Sub

        Private Sub RadGridView1_ViewRowFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.RowFormattingEventArgs) Handles RadGridView1.ViewRowFormatting

        End Sub

        Private Sub RadGridView1_ViewColumnsChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.Data.NotifyCollectionChangedEventArgs) Handles RadGridView1.ViewColumnsChanged

        End Sub

        Private Sub RadRadioButton2_ToggleStateChanged(ByVal sender As System.Object, ByVal args As Telerik.WinControls.UI.StateChangedEventArgs) Handles RadRadioButton2.ToggleStateChanged

        End Sub
    End Class

  10. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 29 Jan 2010 Link to this post

    Hi Kirk,

    I am glad to hear that you have resolved the issue and thank you for sharing your solution with the community. If you have any further questions, please don't hesitate to write us.

    Regards,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WinForms is Visual Studio 2017 Ready