Solved

Visual Basic DataGrid with Headers & format it

Posted on 2009-05-06
10
283 Views
Last Modified: 2013-11-26
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
Comment
Question by:rayluvs
  • 5
  • 4
10 Comments
 
LVL 13

Assisted Solution

by:game-master
game-master earned 400 total points
ID: 24321543


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
 

Author Comment

by:rayluvs
ID: 24322092
ok...worked!

What about formatting it woth currency, comma & right align?
0
 
LVL 13

Accepted Solution

by:
game-master earned 400 total points
ID: 24322357

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:rayluvs
ID: 24324203
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
 
LVL 13

Assisted Solution

by:game-master
game-master earned 400 total points
ID: 24324241


what database are u using?
0
 
LVL 5

Assisted Solution

by:BrianVSoft
BrianVSoft earned 100 total points
ID: 24324358
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
 

Author Comment

by:rayluvs
ID: 24326909
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
 

Author Comment

by:rayluvs
ID: 24327663
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
 
LVL 13

Expert Comment

by:game-master
ID: 24410051


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
 

Author Comment

by:rayluvs
ID: 24660309
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

828 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