Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1076
  • Last Modified:

Format Cells in a Flexgrid

Hi Folks,
Is there any easy way to format one of my clumns as currency in a flexgrid?

Ta
0
davemckenna
Asked:
davemckenna
  • 4
  • 3
1 Solution
 
ShauliCommented:
There is no way to format the entire column. However, you can format the data while you add it to the grid, as in:

MSFlexGrid1.TextMatrix(Row, Column) = FormatCurrency(yourvalue, 2)

S
0
 
davemckennaAuthor Commented:
I think i should elaborate on this i want to be able to select a column and display the results as currency

this is my sql (which does not work!)

"SELECT *, FormatCurrency[Total Payable]) AS Cost FROM InvoiceItems"

I have also tried selecting only one field
"SELECT [Item Number], FormatCurrency[Total Payable]) AS Cost FROM InvoiceItems"

Any thoughts?
0
 
ShauliCommented:
Is it a bound flexgrid? Or do you add the rows while looping through the recordset. The reason for the question is, that you *cannot* set a format to the entire column in a flexgrid. As far as I know the control does not have such an option. So the only way to format a cell in a flexgrid is to format it while you add it to the grid, as in my sample above. If this is a bound control, then what you can do is to loop through the rows right after you show the grid and reformat it, as in:

Dim fLoop As Integer

For fLoop = 0 To MSFlexGrid1.Rows - 1
   MSFlexGrid1.TextMatrix(fLoop, columnnumber) = FormatCurrency(MSFlexGrid1.TextMatrix(fLoop, columnnumber), 2)
Next fLoop

'Please modify columnnumber with the column number to format.

S
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
davemckennaAuthor Commented:
Hi Shauli,
Apologies but i did not see your comment until after i had posted my last one. I though i had better elaborate on my first question as i though it was a bit vague, it was not meant as a response to your comment.

Anyway thanks for the response, i have modified your code and placed it in a command button to format the flexgrid but i get a 'type mismatch error', code is below any thoughts?

Dave

Private Sub Command8_Click()
Dim fLoop As Integer

For fLoop = 0 To GridInvoiceDetails.Rows - 1
   GridInvoiceDetails.TextMatrix(fLoop, 6) = FormatCurrency(GridInvoiceDetails.TextMatrix(fLoop, 6), 2)
Next fLoop

End Sub
0
 
davemckennaAuthor Commented:
This is my form load code:

   Dim MsgText As String

   txtSQL = "SELECT * " + " FROM InvoiceItems " + "WHERE " + "[Invoice Number] = " + (InvoiceNumber)
   Set GridInvoiceDetails.DataSource = _
   ExecuteSQL(txtSQL, MsgText)

   Exit Sub
0
 
ShauliCommented:
That is because you have empty cells, try this one:

Private Sub Command1_Click()
Dim fLoop As Integer

For fLoop = 0 To GridInvoiceDetails.Rows - 1
    If GridInvoiceDetails.TextMatrix(fLoop, 6) <> "" Then
        GridInvoiceDetails.TextMatrix(fLoop, 6) = FormatCurrency(GridInvoiceDetails.TextMatrix(fLoop, 6), 2)
    End If
Next fLoop

End Sub

S
0
 
davemckennaAuthor Commented:
Hi shauli,  did it again with the simultaneous postings!!! I just switched the floop to 1 and  it (I presume) ignored my column headers, thanks for your help. I will try you new code also.

Dave
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now