Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Vertical Text In Datagridview Column Header
tomtrak
post Jul 31 2006, 08:09 AM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 1
Joined: 29-July 06
Member No.: 14,823



Hi,

I don't know how to rotate a text in a DataGridView column header to be written vertically from bottom to top.
I found a property called GdiVerticalFont in a datagridview ColumnHeadersDefaultCellStyle, but it doesn't work.
I don't have any experience in programming user controls so I hope that someone help me to find a good solution. I would be grateful for any tip how to modify an existing control, where to put the code and what to modify.

Thanks in advance
Go to the top of the page
 
+Quote Post
tansqrx
post Aug 2 2006, 10:54 PM
Post #2


Super Member
Group Icon

Group: [HOSTED]
Posts: 533
Joined: 25-April 05
Member No.: 4,374



I fooled around with trying to get this to work for about 3 hours today with little success. This is what I have found out so far. It looks like using ListView is going to be a dead end. It doesn’t appear to offer any methods for adding custom column types. I have also seen that Microsoft has replaced the DataGrid with DataGridView. Looks like there are some good improvements but many of the examples that I was going to give you have methods not included in DataGridView.

From what I can tell right now this is what you will have to do.

1. Get your DataGridView setup with you data bindings, etc.
2. Create a new class that inherits DataGridViewTextBoxCell
3. Within DataGridViewTextBoxCell, setup all of the text rotations as described in my rotating text tutorial.
4. Add the new column type to the DataGridView.

I will work some more on this later. It appears that this may turn out to be quite a project. In the meantime you might want to refer to some of the following links.

http://msdn2.microsoft.com/en-us/library/7fb61s43.aspx
http://msdn2.microsoft.com/en-us/library/ms299610.aspx
Go to the top of the page
 
+Quote Post
christy
post Apr 22 2007, 06:08 PM
Post #3


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 1
Joined: 22-April 07
Member No.: 21,593



QUOTE(tomtrak @ Jul 31 2006, 01:39 PM) *
Hi,

I don't know how to rotate a text in a DataGridView column header to be written vertically from bottom to top.
I found a property called GdiVerticalFont in a datagridview ColumnHeadersDefaultCellStyle, but it doesn't work.
I don't have any experience in programming user controls so I hope that someone help me to find a good solution. I would be grateful for any tip how to modify an existing control, where to put the code and what to modify.

Thanks in advance



Hi,

try the following code,

Private Sub dgv_rmxOrdDetail_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgv_rmxOrdDetail.CellPainting

If e.RowIndex = -1 Then

e.PaintBackground(e.CellBounds, True)
e.Graphics.TranslateTransform(e.CellBounds.Left, e.CellBounds.Bottom)
e.Graphics.RotateTransform(270)
e.Graphics.DrawString(e.FormattedValue.ToString, e.CellStyle.Font, Brushes.Blue, 5, 5)
e.Graphics.ResetTransform()
e.Handled = True
End If

End Sub

To run this effectively, RowHeader.Visible should be false.

This code is working very properly for me.

bye
Go to the top of the page
 
+Quote Post
mazel
post Aug 29 2007, 05:43 AM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 29-August 07
Member No.: 24,443



Hi!

I tried the code that Christy provided. The code didn't go as I've hoped it would, eventhough I've set the RowHeader.Visible to false. And I can't understand how I could change the location of the text. The location of the text was messed up in my program.

But I found another way of implementing this. smile.gif Using the code above :

CODE
Private Sub dgv_rmxOrdDetail_CellPainting(ByVal sender As Object, ByVal e As
         System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgv_rmxOrdDetail.CellPainting

    If e.RowIndex = -1 Then
          Dim sf As New StringFormat(Drawing.StringFormatFlags.DirectionVertical)
          sf.Alignment = StringAlignment.Center

          e.PaintBackground(e.CellBounds, True)
          // e.Graphics.TranslateTransform(e.CellBounds.Left, e.CellBounds.Bottom)
          // e.Graphics.RotateTransform(270)
          e.Graphics.DrawString(e.FormattedValue.ToString, e.CellStyle.Font, Brushes.Blue, e.CellBounds, sf)
          // e.Graphics.ResetTransform()
          e.Handled = True
    End If
End Sub


I can't remember where I've found this. I think the only problem here is that the text is facing the other side (which is the left side). I still can't figure out how I would rotate it. mellow.gif

This post has been edited by mazel: Aug 29 2007, 05:49 AM
Go to the top of the page
 
+Quote Post
tansqrx
post Aug 30 2007, 03:56 PM
Post #5


Super Member
Group Icon

Group: [HOSTED]
Posts: 533
Joined: 25-April 05
Member No.: 4,374



I will say that you should have much more luck with DataGridView over DataGrid. I started using DataGridView about a year ago and I have to say that Microsoft added some MUCH need functionality.
Go to the top of the page
 
+Quote Post
iGuest
post Jun 12 2008, 07:16 AM
Post #6


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



Deferent Language Books Name Display in Datagrid. How to Change Font?
Vertical Text In Datagridview Column Header

Hi I am Lenu Thomas from INDIA,

There is Deferent Language in India; I am making Library Books Software, I am using �Vb.Net Visual Basic Datagrid� Deferent Language books Name Display in Datagrid. How to Change Font?

I show this Model

No. Book Name Language Price Year Authors Publish
1. The Patmos English 150 2000 Colin Warner OM Publsh
2. ThZ]pkvXI Dt Malayalam 70 1900 Charles John OM Publsh
3. and�ġv F�p t Hindi 300 2005 Abd-Ul - %.. ISPCK

Number 2 Display Malayalam Name, Number 3 Display Hindi Name, How to change in Datagrid Cell

I am Using to Deferent Font this is not work. Please Help send Sample code from VB.Net Visual Basic

My E-Mail lenuthomas att hotmail.Com

-question by Lenu Thomas
Go to the top of the page
 
+Quote Post
iGuest
post Jul 13 2008, 07:33 AM
Post #7


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



Window based Application About datagridview Control
Vertical Text In Datagridview Column Header

How to resize datagridview column using seperator (between two columns-( | ) Seperator ) by doubleclick


I want column resize on seerator double click

Reply me as soon as possible


-reply by Manoj
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Finding The Current Line Number In A Text Box(1)
  2. Updating Values In A Text Box(11)


 



- Lo-Fi Version Time is now: 13th October 2008 - 09:34 PM