?
Solved

Visual Basic DataGrid with Headers & format it

Posted on 2009-05-06
10
Medium Priority
?
297 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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

764 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