We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Changing Column Header Name

How can I change the column name of the datagrid? Since the datagrid is bound to the database, the column name automatically shows whatever field name is in the database. In addition, how do I change the width of a certain cell in the datagrid. Ex: the email field in the datagrid has to be wider! I would really appreciate it if you can provide me some codes in the vb.net language b/c all the resource I've found has been in C# and I haven't been successful in converting it into VB.net.

3 Replies

CB Clay Burch Syncfusion Team June 3, 2002 05:39 AM UTC

If you have created a dataset from a datacomnnection and dataadapter dropped on a form, then code such as listed below should allow you to get at the columnstyles where you can set up properties like columnwidth and headertext.
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'add a datasource to the grid
        Me.DataGrid1.DataSource = Nothing
        SqlDataAdapter1.Fill(Me.DataSet11, "FAQEntries")
        Me.DataGrid1.DataSource = Me.DataSet11.Tables("FAQEntries")

        'create a tablestyle based on the current contents
        Dim myCurrencyManager As CurrencyManager
        myCurrencyManager = CType(BindingContext(Me.DataSet11, "FAQEntries"), CurrencyManager)
        Dim ts As DataGridTableStyle
        ts = New DataGridTableStyle(myCurrencyManager)

        'add the tablestyle to grid
        DataGrid1.TableStyles.Add(ts)

        'modify particular columnstyles in the tablestyle
        ts.GridColumnStyles(1).Alignment = HorizontalAlignment.Right
        ts.GridColumnStyles(2).Width = 30
        ts.GridColumnStyles(4).HeaderText = "test"

    End Sub


JO jolly June 3, 2002 08:10 AM UTC

What is the CurrencyManager?


CB Clay Burch Syncfusion Team June 3, 2002 12:35 PM UTC

It is a class in the .NET Framework. It keeps track of what item is 'current', and allows you to get its position, value, count etc. Take a look at the help. You do not actually have to use the currencymanager in the above code. But by using using it, you avoid having to loop through and creating/adding columnstyles yourself.

Loader.
Live Chat Icon For mobile
Up arrow icon