Solved

Column header not middle centered in vb.net

Posted on 2014-02-20
1
319 Views
Last Modified: 2014-02-21
Hi all.

I have the code below and I included the code for one of the columns. What is happening is if the column header is "word wrapped" then it is no longer centered so it looks weird because the data in the row is centered but the column header is not perfectly centered but slightly to the left.

I've read that a fix is to remove the sorting, but we need the sorting for the datagrid.

Any idea how I can fix this?

DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True     'Word wrap 
        DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells  'Adjust the height of the rows
        DataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter    'Center in the middle cell contents
        DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter   'Center in the middle the column headers
        DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray
        DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText

        DataGridView1.AutoGenerateColumns = False

        DataGridView1.ColumnCount = 8   'Set Columns Count

        'Add Columns

        DataGridView1.Columns(0).Name = "MasterItemNumber"
        DataGridView1.Columns(0).HeaderText = "Master Item Number"
        DataGridView1.Columns(0).DataPropertyName = "MasterItemNumber"
        DataGridView1.Columns(0).Width = 120

Open in new window

0
Comment
Question by:printmedia
1 Comment
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39876942
Column header will be slightly to the left to leave room for the sorting indicator. So if you want it to be perfectly centred but also want to allow sorting then you would probably need to custom render it.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now