Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual Basic DataGrid with Headers & format it

Posted on 2009-05-06
10
Medium Priority
?
303 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
[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
  • 5
  • 4
10 Comments
 
LVL 13

Assisted Solution

by:game-master
game-master earned 1600 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 1600 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
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.

 

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 1600 total points
ID: 24324241


what database are u using?
0
 
LVL 5

Assisted Solution

by:BrianVSoft
BrianVSoft earned 400 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

650 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