This is a migrated thread and some comments may be shown as answers.

Column headers in radGridView

3 Answers 903 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sandi Markon
Top achievements
Rank 1
Sandi Markon asked on 07 Jan 2011, 12:06 PM
Column header texts and sizings are not accepted regardless if they are set through property builder or through columns property. If AutoGenerateColumns is set to true, database column names in default sizing are displayed, if AutoGenerateColumns is set to false, nothing is displayed.

3 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 07 Jan 2011, 12:37 PM
Hello Sandi,

Below is an example of setting the header text for a column when AutoGenerateColumns = True and also setting the font and colour for a header cell.
Imports Telerik.WinControls
Imports Telerik.WinControls.UI
Imports System.ComponentModel
  
  
Public Class Form1
  
  
    Private Sub Form1_Load(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles MyBase.Load
  
        Me.RadGridView1.AutoGenerateColumns = True
  
        ' create some columns
        Me.RadGridView1.Columns.Add(New GridViewCheckBoxColumn("MyCheckBox"))
        Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("MyTextBox1"))
        Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("MyTextBox2"))
        Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("MyTextBoxUser1"))
        Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("MyTextBoxUser2"))
  
        ' Set the Header Text to whatever you want
        Me.RadGridView1.Columns("MyTextBox1").HeaderText = "Custom Header text"
  
        ' populate the grid
        Me.Populate()
    End Sub
  
    Private Sub Populate()
        'Simulate getting data from SQL via a reader
        For i As Integer = 1 To 4
            Dim rowInfo As GridViewRowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells("MyCheckBox").Value = False
            rowInfo.Cells("MyTextBox1").Value = "MyTextBox1 Value " & i.ToString()
            rowInfo.Cells("MyTextBox2").Value = "MyTextBox2 Value " & i.ToString()
            rowInfo.Cells("MyTextBoxUser1").Value = ""
            rowInfo.Cells("MyTextBoxUser2").Value = ""
        Next i
    End Sub
  
    Private Sub RadGridView1_ViewCellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting
        If TypeOf e.CellElement Is GridHeaderCellElement Then
            e.CellElement.ForeColor = Color.Red
            e.CellElement.Font = New Font("Ariel", 14)
        End If
    End Sub
End Class
  
Public Class MyObject
    Public Sub New(ByVal name As String, ByVal id As Integer)
        Me.Name = name
        Me.Id = id
    End Sub
  
    Public Property Name As String
    Public Property Id As Integer
End Class

hope that helps but if you need more assistance, please let me know
Thanks
Richard
0
Sandi Markon
Top achievements
Rank 1
answered on 07 Jan 2011, 03:21 PM
I have found the reason why the headers did not stay as set. Problem was that datasource has to be converted to list with .ToList() function and in my program it wasn't. Interesting is that data was displayed anyway, just the headers were corrupted.
BTW thanks for your answer Richard.
0
Richard Slade
Top achievements
Rank 2
answered on 07 Jan 2011, 03:22 PM
Ok, glad you have found a solution
If you need further help, please let me know
Regards,
Richard
Tags
GridView
Asked by
Sandi Markon
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Sandi Markon
Top achievements
Rank 1
Share this question
or