Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How To set Header Text in DataGrid Window Application.

Chandan ThourChandan Thour Member Posts: 20
Hi There,

How can we set the Header Text of a DataGrid in a Window Application.

In My application. User will insert information in the cells of datagrid from where it will be stored in db. So Dataset stuff is not valid.

I need to write my columns Header name by myself.

Setting the Header text is the only problem i am facing. Can anyone help?


  • munirshahzadmunirshahzad Member Posts: 59
    There are two ways to do it.
    Select DataGrid, comes to Properties and click on TableStyles. Click Add to add a table style. Now Click GridColumnStyle. Here again Click Add to add a column Style. In column Style Properties you have a property HeaderText.

    Public Class frmEditEmployeeCourses

    Dim Table_Style_Once As Boolean = True

    Sub DataGrid()
    Dim Educational_Da As New SDS.OleDbDataAdapter("Select * from Customers", Courses_Cn)
    Dim Educational_Ds As New DataSet()
    Educational_Da.Fill(Educational_Ds, "Customers")
    If Me.Table_Style_Once Then
    Me.Table_Style_Once = False
    End If
    Me.dgBrowseCourses.DataSource = Educational_Ds.Tables("Customers")
    Me.dgBrowseCourses.CaptionText = "Customers Found : " & Me.BindingContext(Educational_Ds, "Customers").Count
    Catch Ex As Exception
    MsgBox(Ex.Message, MsgBoxStyle.Critical, "DataGrid Error")
    End Try
    End Sub

    Sub DataGrid_Styles()
    Dim grdColStyle1 As New DataGridTextBoxColumn()

    With grdColStyle1 : .HeaderText = "Customer Name" : .MappingName = "CName" : .Width = 34 : End With

    Dim grdTableStyle1 As New DataGridTableStyle()
    grdTableStyle1.MappingName = "Customers"

    grdTableStyle1.GridColumnStyles.AddRange _
    (New DataGridColumnStyle() _
    End Sub
    End Class
Sign In or Register to comment.