CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Having problems aligning numbers to the left of the cell, in an MSFlexGrid.

  1. #1
    Join Date
    Jul 2002
    Posts
    7

    Having problems aligning numbers to the left of the cell, in an MSFlexGrid.

    Before I load the data I set the horizontal and vertical alignment of data within the current cell to the left. FlexGrid.CellAlignment = 2. After I load the grid from the database, if any of the cells have data that contains a number, like '12', that cells data will be align to the right. How can I make all the data align left?


    Thanks Jim

  2. #2
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    Hi Jim,

    I'm not a FlexGrid expert, I actually align the text using the FormatString parameters:

    Code:
    Private Sub Command1_Click()
           
        'Set the alignement for each colonne    
        Me.MSFlexGrid1.FormatString = "<LeftAlign               |>RighAlign              "
     
        'Look the alignement
        Me.MSFlexGrid1.TextMatrix(1, 0) = "Kobold"
        Me.MSFlexGrid1.TextMatrix(1, 1) = "Kobold"
       
        Me.MSFlexGrid1.AddItem "hello"
    
        'The number will be align left
        Me.MSFlexGrid1.AddItem "12"
        
    
    End Sub
    hope it helps -- Jeff

  3. #3
    Join Date
    Jun 2002
    Location
    Canada
    Posts
    23
    You can also align values in the centreusing the format string.

    Me.MSFlexGrid1.FormatString = "^Center "

    In code you can also use the cellalignment property to align values in a cell.
    Thanks and Good Luck!!

    zemp

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    To tell it in code...

    'need to set the cellalignment of each cell. Thus you have to cycle
    throug them. As you have to do it, you can assign values the old
    way, without using textmatrix or textarray...
    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim intCol, intRow
    With MSFlexGrid1
       .Cols = 5
       .Rows = 5
       For intRow = 1 To .Rows - 1
          For intCol = 1 To .Cols - 1
             .Row = intRow
             .Col = intCol
             'first put value
             .Text = intRow
             'then allign
             .CellAlignment = flexAlignLeftCenter
          Next
       Next
    End With
    End Sub
    Have happy coding,

    Cesare Imperiali
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)