• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Visual Basic DataGrid with Headers & format it

We have a VB6 apps using DataGrid.

We have manage to show the grid with the SQL data.  We need to add the Headers & format the sales.

We :
- We set the form
- add the ADODC object
- at form load() we set the select as follows (which displays perfectly on the form):

Private Sub Form_Load()
 Dim sSql As String
 sSql = "select Departmment, Region, Sales from Territorial"
 adocTerritorial.ConnectionString = cnn
 adocTerritorial.RecordSource = sSql
 adocTerritorial.Refresh
End Sub

We need to custiomize title and format Sales to $xxx.xx
0
rayluvs
Asked:
rayluvs
  • 5
  • 4
4 Solutions
 
game-masterCommented:


on your sql statement change format or field to whatever you want...
sumthing like this....

sSql = "select Departmment as DEPARTMENT, Region as REGION, Sales as MYSALES from Territorial"

in this exmaple, change the capitalize text with your preferred header...


i hope i can give u idea...


game-master
0
 
rayluvsAuthor Commented:
ok...worked!

What about formatting it woth currency, comma & right align?
0
 
game-masterCommented:

FORMAT depends on the type on database ur using...
and the for the alignment...

datagrid columns has alignment property...

sumthng like this...

DataGrid1.Columns(1).Alignment = dbgRight


game-master
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
rayluvsAuthor Commented:
Somehow its not working, no effect on the screen; still show the actual SQL string result with the difference, the Title you showed me.

The display shows the grid as follows:

Department      Region      Sales
-------------- ------------  ------------
San Fran        SouthE      6559.36
New York       West-Q    256314.1
Jersey            North-W   501.06

And I need it to be:

Department      Region             Sales
-------------- ------------  ----------------
San Fran        SouthE         $65,59.36
New York       West-Q    $256,314.10
Jersey            North-W          $501.06
0
 
game-masterCommented:


what database are u using?
0
 
BrianVSoftCommented:
Hi Ramante..
This is a copy of an answer I gave to one of your other questions..
The FlexGrid can be bound to a DataObject and therefore might solve both your problems?

Copied answer..
If you have one of the later ServicePacks for VB (eg. 6) you can use the FlexGrid..
Very powerful tool for displaying this sort of data..
Use any font (don't need fixed width)
Columns can be justified Left, Center or Right..
Vertical Scroll bar

Sample code as follows..

Private Sub RunReport_Click()

 With MSFlexGrid1 ' ' Microsoft FlexGrid Control 6.0 (in system32\Msflxgrd.ocx)
 .Clear: .Rows = 1: .Cols = 3
 .GridLines = 0: .GridLinesFixed = 0 ' Remove vertical lines.
 .FixedCols = 0
 .ColWidth(0) = 1400: .ColWidth(1) = 1200: .ColWidth(2) = 1800
 .FormatString = "<ITEM CODE|>COST PRICE|<. REFERENCE.." ' Note the Alignment Chars < (LeftJust), > (RightJust), ^ (Center)
 
  For TestCount = 1 To 99 ' Replace this with your "Do Until xxx.EOF"
    .AddItem "MyData" & Str(TestCount) & vbTab & Format(Rnd * 10000, "###,##0.00") & vbTab & "  MyReference" & Str(TestCount)
 
  Next TestCount
 
  If .Rows > 1 Then .FixedRows = 1 ' Placed at end because 'FixedRows' gives an error if Rows < 1
 End With
 
End Sub
0
 
rayluvsAuthor Commented:
I am using SQL 2000.  I have formatted the SELECT prior diaplsy, but it still shows as its saved in the table.

Hi BrianVSoft, that the question I was looking for.  Can you tell which question it was?

I revied my code, I dont have MSFlexGrid1 included.  MSFlexGrid1 is better that MSDATGRID.ocx?
0
 
rayluvsAuthor Commented:
I hope you don't mind we stick to DataGrid at this point.  Just found out that the entire apps are in DataGrid I dont want to change my programmer scheme (he out of the country).

I just saw his apps and all  DataGrids have Headers.. yet I search within the apps and can;t find where the Headers is defined.  

On the app I am working on I need to place.  Can someone tell me where I can change the Header and format the columns (I know that the answer of placing the titles worked, but my app has to be consisten as the rest and the rest of the apps has formatted headers)
0
 
game-masterCommented:


Unfortunately, u cannot able to format the header the way u like it..
That is sumhow, the limitation of the datagrid control...

Datagrid is binded to your recordset.


game-master
0
 
rayluvsAuthor Commented:
Hi I did find a way to change the header of the DataGrid:

going to the properties of the datagrid and choosing columns and entering the changes in "Caption".

Just to say that game-master also works.

Thanx all
0

Featured Post

Industry Leaders: 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!

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