?
Solved

Format Cells in a Flexgrid

Posted on 2005-04-04
7
Medium Priority
?
1,061 Views
Last Modified: 2008-03-10
Hi Folks,
Is there any easy way to format one of my clumns as currency in a flexgrid?

Ta
0
Comment
Question by:davemckenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 13702766
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
 

Author Comment

by:davemckenna
ID: 13702796
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
 
LVL 19

Accepted Solution

by:
Shauli earned 2000 total points
ID: 13702928
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
Technology Partners: 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!

 

Author Comment

by:davemckenna
ID: 13710019
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
 

Author Comment

by:davemckenna
ID: 13710095
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
 
LVL 19

Expert Comment

by:Shauli
ID: 13710469
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
 

Author Comment

by:davemckenna
ID: 13710518
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question