MS Flexgrid Cell Alignment
I am populatiing data into MSFlexgrid. One field is related to Address of the person. A problem is coming now:
If the address begins with number like 14,Xyz Street,City-111 111 then it is aligned right but if the address starts with alpabhets say, Shop No. 14A, Xyz street, City - 111 111 then it is left aligned.
How can this be rectified?
Re: MS Flexgrid Cell Alignment
Set the CellAlignment property. Valid values are: flexAlign[Left|Center|Right][Top|Center|Bottom] (for example flexAlignLeftTop) or flexAlignGeneral which will align to the left for text and right for numbers (which is the default).
Re: MS Flexgrid Cell Alignment
Thanks Joacim, its working.
I have not found the cellAlignment property in the property box but used the same in code as:
Grid1.CellAlignment = flexalignleft
Now it works well
One more thing if you can help me:
I want to keep the Headers name in Centre ie text alignment of Row 0 should only be Centre align. How can thias be done?
Re: MS Flexgrid Cell Alignment
The CellAlignment property only sets the Alignment for the current selected cell so it is not available during design-time.
When it comes to the headers I think you can use the CellAlignment property on those as well. First set the Col and Row properties to select the correct header cell and then set the CellAlignment property.
Re: MS Flexgrid Cell Alignment
I realize this is an old topic and no one really cares, but I figured that since I've been trying to find the answer to this problem online for the past four days and no one has come close to answering it for me I finally stumbled upon the answer and I figured I would share it with the rest of you looking for the answer yourself! Here's the problem...
You have a bunch of text data all in columns and you're using a MSFlexGrid to give you a nice and pretty little display of that data. However it don't look so nice and pretty because for some reason if the data begins with a number even thou it is text the alignment if thrown completely off and looks terrible. Its because that any data that begins with a number by default is right aligned (if it also contains text) and centered if it's a number only. For example... you've got the following data you'd like to place in a column and how it looks:
|........1234.........|
|.876 Oak Dr..........|
|PO Box 19............|
|TNMT.................|
|.99 Red Luft Balloons|
Looks terrible right (Imagine the dots being spaces and the lines being the sides of the datagrid field ... c'mon, use a little imagination here peoples!)? I mean who the heck thought that making the default of the control behave like this was a good idea? Not me that's for sure... Well... Here's what I have found that didn't help... using
MSFlexGrid.CellAlignment = flexAlignLeftCenter
on each cell did not work... Neither did...
MSFlexGrid.ColAlignment = flexAlignLeftCenter
The only thing that actually worked was when you changed the column header cells with .FormatString... Yeah that's right... .FORMATSTRING! Here's the code I used using the exact same data above in three different columns:
Code:
dim Data(5) as String
Data(1) = "1234"
Data(2) = "876 Oak Dr"
Data(3) = "PO Box 19"
Data(4) = "TNMT"
Data(5) = "99 Red Luft Balloons"
With MSFlexGrid1
.Clear
.CellAlignment = flexAlignLeftCenter ' Don't work... but it's here to show ya how I used it
.WordWrap = False ' You sometimes get weird wrapping issues, turn it off
.Rows = 6 ' Don't forget, you're gonna have a header row at 0
.Cols = 4 ' and usually a header column at 0
.FixedRows = 1
For x = 1 to 5
.TextMatrix(1, x) = Data(X)
.TextMatrix(2, x) = Data(X)
.TextMatrix(3, x) = Data(X)
.CellAlignment = FlexAlignLeftCenter ' Again... didn't work! Just for clairity!
Next x
' ****************************************************************************************************************
' Now here's where the magic happens... When placing the column names place a < or > in front of the name itself
' (don't worry, it won't be displayed with the name) depending on how you want that column to be aligned (putting
' nothing there it will default to what you have been fighting to get rid of!
' ****************************************************************************************************************
ColTitles = "<Column1" & vbTab & ">Column2" & vbTab & "Column3"
' ****************************************************************************************************************
' Note: If you put a < in front of the column title the whole column data aligns to the left
' If you put a > in front of the column title the whole column aligns to the right
' and if you don't put anything there the entire column is screwed up again!
' ****************************************************************************************************************
.FormatString = ColTitles ' Let's put the magic to work for us for a change!
End With
Now... if you notice the first column is left aligned, the 2nd column is right aligned and the 3rd is what we started with that we've been trying to fix. I hope this helps someone out there... Lemme know if this helps you!
-=> Jim! <=-
Re: MS Flexgrid Cell Alignment
try this:
.ColAlignment(x) = flexAlignLeftCenter