GridView.Rows[].TextAlign is a new feature in 3.14
Is it possible to have the text in a column header aligned center and have the column data aligned left?
Gridview column header alignment
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
- Got2BeFree
- Posts: 91
- Joined: Saturday 26th November 2016 2:52am
- Location: Lost
Re: Gridview column header alignment
It is done similar to how the header is aligned.
From one of my database projects:
From one of my database projects:
For Each MGlobal.hResData
gvViewer[iRow, 0].Text = Str$(Format(DateAdd(CDate("1/1/1970"), gb.Second, MGlobal.hResData!date), mm/dd/yyyy hh:nn:ss ddd")) ' convert from unix timestamp
gvViewer[iRow, 0].Alignment = Align.Right
gvViewer[iRow, 1].Text = MGlobal.hResData!name
gvViewer[iRow, 1].Alignment = Align.Right
gvViewer[iRow, 2].Text = MGlobal.hResData!location
gvViewer[iRow, 2].Alignment = Align.Right
gvViewer[iRow, 3].Text = MGlobal.hResData!leave
gvViewer[iRow, 3].Alignment = Align.Right
gvViewer[iRow, 4].Text = MGlobal.hResData!comment
gvViewer[iRow, 4].Alignment = Align.Right
Inc iRow
Next
If you need to only align, for example, the cells in the 3rd column, you also have to align column cells 0 thru 2. (At least it wouldn't for me.)sholzy
I'm wondering around lost in the past, not knowing where the present is.
I'm wondering around lost in the past, not knowing where the present is.
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: Gridview column header alignment
Thanks Got2BeFree, I hope I've not misunderstood your sugestion but my question is about columns.
If I change the alignment of any cell in a column, all the cells in that column are changed
If I change the alignment of any cell in a column, all the cells in that column are changed
- Got2BeFree
- Posts: 91
- Joined: Saturday 26th November 2016 2:52am
- Location: Lost
Re: Gridview column header alignment
EDIT: Scratch reply below and my reply above. I just went back and reread your question for the hundredth time and just realized what you wrote is for the newest release. I haven't upgraded yet so just ignore me.
Without actually looking at the new command, I would venture a wild guess that it would work similar to what I've already described. I'm off to see if I'm able to upgrade so I can figure this out properly....
The only way I've been able to align a cell differently from it's header is by changing a cell's alignment individually. It takes 2 different commands, one to align headers in one direction, and one to align the cells below that header in another direction.
The .Columns[x].Alignment = aligns the header and the cells of the whole column below that header. To change the alignment of the cells below the header, you will need to change the alignment of each cell in that column row by row ( GridView[x,x].Alignment = ). And, to change the alignment of each of the cells for a column, you also need to align the cells in the columns before it, you can't just align the cells in column 2 without aligning the cells in columns 0 and 1.
Without actually looking at the new command, I would venture a wild guess that it would work similar to what I've already described. I'm off to see if I'm able to upgrade so I can figure this out properly....
The only way I've been able to align a cell differently from it's header is by changing a cell's alignment individually. It takes 2 different commands, one to align headers in one direction, and one to align the cells below that header in another direction.
The .Columns[x].Alignment = aligns the header and the cells of the whole column below that header. To change the alignment of the cells below the header, you will need to change the alignment of each cell in that column row by row ( GridView[x,x].Alignment = ). And, to change the alignment of each of the cells for a column, you also need to align the cells in the columns before it, you can't just align the cells in column 2 without aligning the cells in columns 0 and 1.
sholzy
I'm wondering around lost in the past, not knowing where the present is.
I'm wondering around lost in the past, not knowing where the present is.
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Gridview column header alignment
You need a Gridview on a form to run this but it works.
Dim iRow, iCol As Integer
Dim sText As String[] = ["One", "Two", "Three", "Four", "Five"]
GridView1.Columns.Count = sText.Count
GridView1.Rows.Count = sText.Count
For iCol = 0 To sText.Max
GridView1.Columns[iCol].Title = sText[iCol]
GridView1.Columns[iCol].Alignment = Align.Center
Next
For iCol = 0 To sText.Max
For iRow = 0 To sText.Max
GridView1[iRow, iCol].Text = sText[iRow]
GridView1[iRow, iCol].Alignment = Align.Left ''If you take this out all will be centred
Next
Next
- Got2BeFree
- Posts: 91
- Joined: Saturday 26th November 2016 2:52am
- Location: Lost
Re: Gridview column header alignment
Your example is the same as what I had (mine less detail) before realizing what I was doing wasn't what Bill is wanting to know.cogier wrote: ↑Thursday 5th December 2019 6:23pm You need a Gridview on a form to run this but it works.
Dim iRow, iCol As Integer Dim sText As String[] = ["One", "Two", "Three", "Four", "Five"] GridView1.Columns.Count = sText.Count GridView1.Rows.Count = sText.Count For iCol = 0 To sText.Max GridView1.Columns[iCol].Title = sText[iCol] GridView1.Columns[iCol].Alignment = Align.Center Next For iCol = 0 To sText.Max For iRow = 0 To sText.Max GridView1[iRow, iCol].Text = sText[iRow] GridView1[iRow, iCol].Alignment = Align.Left ''If you take this out all will be centred Next Next
I believe what bill-lancaster is referring to is a new property to align the cell text in the newest release. I'm not able to upgrade yet to test, and I don't see the new property yet in the wiki to see how it works.
sholzy
I'm wondering around lost in the past, not knowing where the present is.
I'm wondering around lost in the past, not knowing where the present is.
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: Gridview column header alignment
Thank you very much, that's perfect
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Gridview column header alignment
Looking into GridView.Rows[].TextAlign further I discovered this quote from the GitLab page here.
Here is some code to demonstrate this feature. Unless I have missed something it is not the most exciting feature!
The alignment of the row numbers is 'Center' by default and the only alignment changes that seem to work are 'Left' and 'Right'. You also need to create a lot of rows so that you can see the result.GridView: GridView.Rows[].TextAlign is a new property that allows to define the alignment of the row header text.
Here is some code to demonstrate this feature. Unless I have missed something it is not the most exciting feature!
''Requires a Gridview on the form
Public Sub Form_Open()
Dim iRow, iCol As Integer
Dim sText As String[] = ["One", "Two", "Three", "Four", "Five"]
GridView1.Header = GridView.Both
GridView1.Columns.Count = sText.Count
GridView1.Rows.Count = 10000
For iCol = 0 To sText.Max
GridView1.Columns[iCol].Title = sText[iCol]
GridView1.Columns[iCol].Alignment = Align.Center
Next
For iCol = 0 To sText.Max
For iRow = 0 To sText.Max
GridView1.Rows.Height = 100
GridView1[iRow, iCol].Text = sText[iRow]
GridView1[iRow, iCol].Alignment = Align.Left
Next
Next
GridView1.Rows[0].TextAlignment = Align.Left
GridView1.Rows[2].TextAlignment = Align.Right
GridView1.Rows[3].TextAlignment = Align.Bottom
GridView1.Rows[4].TextAlignment = Align.BottomLeft
GridView1.Rows[5].TextAlignment = Align.BottomNormal
GridView1.Rows[6].TextAlignment = Align.BottomRight
GridView1.Rows[7].TextAlignment = Align.Top
GridView1.Rows[8].TextAlignment = Align.TopLeft
GridView1.Rows[9].TextAlignment = Align.TopRight
GridView1.Rows[10].TextAlignment = Align.TopNormal
End