Solved

Visual Basic DataGrid with Headers & format it

Posted on 2009-05-06
10
274 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wpf develop 5 35
VBA Shell can't Find Word document 11 45
Change data in datatable 8 18
What .NET website keeps me current? 9 32
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now