-
Jun 25th, 2013, 04:44 PM
#1
Thread Starter
Addicted Member
Vertically up Headers
Hi guys, I am trying to design a form with headers that read vertically up. This is to save space so I can fit many columns. I tried datagrid but am not sure how to achieve this. I use WPF and Vb.net. Please suggest any other better solution eg importing an excel or doc table, if that is possible. I have never tried that before. I am a little stuck. Thanks if you can help.
-
Jun 25th, 2013, 08:50 PM
#2
Re: Vertically up Headers
I've been playing around with this for a while with some fairly unspectacular results so the best I can offer at the moment is vertically down headers. Consider this a work in progress!
vb.net Code:
' in the form which has your dgv Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Column1.HeaderCell = New VerticalColumnHeader ' etc. End Sub ' and the class Class VerticalColumnHeader Inherits DataGridViewColumnHeaderCell Protected Overrides Sub Paint(graphics As System.Drawing.Graphics, clipBounds As System.Drawing.Rectangle, cellBounds As System.Drawing.Rectangle, rowIndex As Integer, dataGridViewElementState As System.Windows.Forms.DataGridViewElementStates, value As Object, formattedValue As Object, errorText As String, cellStyle As System.Windows.Forms.DataGridViewCellStyle, advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, paintParts As System.Windows.Forms.DataGridViewPaintParts) MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, "", "", errorText, cellStyle, advancedBorderStyle, paintParts) Dim f As New StringFormat f.FormatFlags = StringFormatFlags.DirectionVertical graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality graphics.DrawString(value.ToString, cellStyle.Font, New Drawing.SolidBrush(cellStyle.ForeColor), 50, 20, f) End Sub End Class
EDIT: Oh, nearly forgot, in the DGV you'll need to set ColumnHeadersHeightSizeMode to EnableResizing so that you can increase ColumnHeadersHeight to a suitable size.
Last edited by dunfiddlin; Jun 25th, 2013 at 08:55 PM.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 25th, 2013, 09:00 PM
#3
Re: Vertically up Headers
As you're overriding the Paint event it's just 1 small step to rotate the text.
Have a look at the Graphics.RotateTransform method
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 25th, 2013, 09:04 PM
#4
Re: Vertically up Headers
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 25th, 2013, 09:12 PM
#5
Re: Vertically up Headers
Originally Posted by .paul.
As you're overriding the Paint event it's just 1 small step to rotate the text.
Have a look at the Graphics.RotateTransform method
Ta muchly but I did try that (and will do so again) but there appear to be complications associated with this cell that I didn't get time to look into (it's 3 in the morning ... why am I even still up?)
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 26th, 2013, 04:06 AM
#6
Thread Starter
Addicted Member
Re: Vertically up Headers
Originally Posted by dunfiddlin
Ta muchly but I did try that (and will do so again) but there appear to be complications associated with this cell that I didn't get time to look into (it's 3 in the morning ... why am I even still up?)
Since I am using WPF I will try the RotateTransform approach. It looks more relevant and to the point. Anyway, thanks for all your replies guys, appreciated.
-
Jun 26th, 2013, 07:26 AM
#7
Re: Vertically up Headers
I really got to learn not to to try topology at 2.00 in the morning! My math was the problem (in this case not remembering which way was up after a rotation!) So here is the working version.
vb.net Code:
Class VerticalColumnHeader
Inherits DataGridViewColumnHeaderCell
Protected Overrides Sub Paint(graphics As System.Drawing.Graphics, clipBounds As System.Drawing.Rectangle, cellBounds As System.Drawing.Rectangle, rowIndex As Integer, dataGridViewElementState As System.Windows.Forms.DataGridViewElementStates, value As Object, formattedValue As Object, errorText As String, cellStyle As System.Windows.Forms.DataGridViewCellStyle, advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, paintParts As System.Windows.Forms.DataGridViewPaintParts)
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, "", "", errorText, cellStyle, advancedBorderStyle, paintParts)
graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
graphics.TranslateTransform(0, cellBounds.Height)
graphics.RotateTransform(270)
graphics.DrawString(value.ToString, cellStyle.Font, New Drawing.SolidBrush(cellStyle.ForeColor), 20, 50)
graphics.ResetTransform()
End Sub
End Class
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jul 1st, 2013, 07:30 AM
#8
Re: Vertically up Headers
Since this is a WPF question, I am going to move this thread to the WPF Forum.
Let me know if you have any questions.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|