How to format MSFlexgrid Colum

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muddasirmunir
    Contributor
    • Jan 2007
    • 284

    How to format MSFlexgrid Colum

    I am using vb6.

    I had placed an MSFlexGrid control in my form , the colum(3) contain quanity of the products.

    Currently , the quantity is shouwing like

    Code:
    10
    1500
    200
    I want to show it like

    Code:
    10.00
    1500.00
    200.00
    I know how to make it round for text boxes to two decimal places by using

    Code:
    Format(Round(quantity.Text, 2), "##0.00")
    But how can I use the same code in MSFlexGrid.

    Any help?
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    It's the same: when adding the value to the grid, format the value like:

    Code:
       For idx = 1 To 10
          MSHFlexGrid1.AddItem (idx & vbTab & Format(Round(idx * 100, 2), "##0.00"))
       Next
    this will give=
    1 | 100.00
    2 | 200.00
    ...

    Comment

    • muddasirmunir
      Contributor
      • Jan 2007
      • 284

      #3
      I am using the following function , where there is no syntax like .additem

      I am posting my syntax , please guide me how to achieve my goal with this

      Private Function fillgrid()

      Code:
      Dim rs As Recordset
      Set rs = New Recordset
      rs.CursorLocation = adUseClient
      rs.CursorType = adOpenStatic
      rs.LockType = adLockOptimistic
      
      If rs.State = adStateOpen Then
      rs.Close
      End If
      
      Dim sSQL As String
      sSQL = "my query"
      rs.Open sSQL, con
      
      Dim i As Integer
      Dim j As Integer
      
      
      grid1.FixedRows = 1
      grid1.FixedCols = 0
      
      If Not rs.EOF Then
      
      grid1.Rows = rs.RecordCount + 1
      grid1.Cols = 1rs.Fields.Count
      
      For i = 0 To rs.Fields.Count - 1
      grid1.TextMatrix(0, i) = rs.Fields(i).Name
      Next
      
      i = 1
      Do While Not rs.EOF
      
      For j = 0 To rs.Fields.Count - 1
      If Not IsNull(rs.Fields(j).Value) Then
      grid1.TextMatrix(i, j) = _
      rs.Fields(j).Value
      End If
      Next
      
      i = i + 1
      rs.MoveNext
      Loop
      
      PopulateFlexGrid = True
      End If
      
      
      End Function

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Change the Populate code like this :

        [code=vb]
        For j = 0 To rs.Fields.Count - 1
        If Not IsNull(rs.Field s(j).Value) Then
        If j = 3 Then
        grid1.TextMatri x(i, j) = Format(rs.Field s(j),"0.00")
        Else
        grid1.TextMatri x(i, j) = rs.Fields(j).Va lue
        End If
        End If
        Next
        [/code]

        Regards
        Veena

        Comment

        • muddasirmunir
          Contributor
          • Jan 2007
          • 284

          #5
          Originally posted by QVeen72
          Hi,

          Change the Populate code like this :

          [code=vb]
          For j = 0 To rs.Fields.Count - 1
          If Not IsNull(rs.Field s(j).Value) Then
          If j = 3 Then
          grid1.TextMatri x(i, j) = Format(rs.Field s(j),"0.00")
          Else
          grid1.TextMatri x(i, j) = rs.Fields(j).Va lue
          End If
          End If
          Next
          [/code]

          Regards
          Veena
          Thanks , Qveen72 , that works

          Comment

          Working...