Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

Display column headers text in datagridview vertically in vb.net 2015

How to display text vertically in a datagridview in vb.net 2015.

In Excel you can format the text in a column to display vertically by going to the alignment tab in Format cells and change the Orientation 90 degrees and the text will display vertically. Is there a way to do that in a datagridview in vb.net 2015.
Avatar of Noah
Noah
Flag of Singapore image

Hi there! :)

I read your requirements and it seems like that there is already a guide online on how to do this. Do refer to the following link to see if it fits what you are looking for.

Code Reference: https://notesbyparth.wordpress.com/2013/07/10/display-datagridview-vertical-vb-net/

Private Sub goProcessData()
        ' Get your data in dataset
        Dim payment As DataSet = SoapWrapper.getPaymentDetails(txtInvNo.Text.ToString().Trim())
        payment = FlipDataSet(payment)
        ' Fill Datagridview
        Dim TableView As DataView
        TableView = payment.Tables(0).DefaultView
        grdCust.DataSource = TableView
End Sub
 
 Private Function FlipDataSet(old_DataSet As DataSet) As DataSet
        Try
            Dim ds As New DataSet()
            For Each dt As DataTable In old_DataSet.Tables
                Dim table As New DataTable()
                ' Creating Columns
                For i As Integer = 0 To dt.Rows.Count
                    table.Columns.Add(Convert.ToString(i))
                    ' Column 0 will be all fields so set your column heading 
                    table.Columns(0).ColumnName = "Fields"
                    If i = 0 Then
                        Continue For
                    Else
                        ' Columns from index 1 will be your values, so headings accordingly
                        table.Columns(i).ColumnName = "Customer " & i
                    End If
                Next
                Dim r As DataRow
                ' Creating Rows
                For k As Integer = 0 To dt.Columns.Count - 1
                    r = table.NewRow()
                    ' Row 0 will always be column name so set your column name here
                    r(0) = dt.Columns(k).ToString()
                    ' Rows from index 1 will be your values
                    For j As Integer = 1 To dt.Rows.Count
                        r(j) = dt.Rows(j - 1)(k)
                    Next
                    table.Rows.Add(r)
                Next
                ds.Tables.Add(table)
            Next
            Return ds
        Catch ex As Exception
            Throw
        End Try
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial