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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Changing Column Header Name

Thread ID:

Created:

Updated:

Platform:

Replies:

321 Jun 3,2002 04:29 AM UTC Jun 3,2002 12:35 PM UTC Windows Forms 3
loading
Tags: FAQ
quilla_b
Asked On June 3, 2002 04:29 AM UTC

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.

Clay Burch [Syncfusion]
Replied On 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

jolly
Replied On June 3, 2002 08:10 AM UTC

What is the CurrencyManager?

Clay Burch [Syncfusion]
Replied On 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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;