Solved

Add and format columns in vb6

Posted on 2016-11-23
7
22 Views
Last Modified: 2016-11-23
Hi, we are fixing a code where it uses datagrid.  

We set at form load the data to display:
 sSql= "select col1, col2, col3 from TableName"
 dcRecs.ConnectionString = cnn
 dcRecs.RecordSource = sSql
 dcRecs.Refresh

Open in new window


Works fine but we need to:
- add column header to each column
- format col3 as numeric 2 decimal value
- format col2 and col3 to be displayed as center

We have tried right-click on datagrid >> properties >> Columns but it only displays 2 columns.  Also we got to increase adding the column in the designer by "Edit", but still  can't seem to get in the Column tab the DataField or in the Format tab the numeric and right-align format.

Please advice.
0
Comment
Question by:rayluvs
  • 4
  • 3
7 Comments
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41899662
DataGrid1.ColumnHeaders = True
DataGrid1.Columns.Add 2 ' The index of columns starts at 0, so this adds the 3rd column
DataGrid1.Columns(0).Caption = "aaa"
DataGrid1.Columns(1).Caption = "bbb"
DataGrid1.Columns(2).Caption = "ccc"

DataGrid1.Columns(2).NumberFormat = "#,##0.00"
DataGrid1.Columns(0).Alignment=dbgCenter
DataGrid1.Columns(1).Alignment=dbgCenter

Open in new window

0
 

Author Comment

by:rayluvs
ID: 41899943
Worked, but we are a bit confused.

Why in design mode it displays 2 columns and when running the apps that has a script with 8 columns it displays 8 columns, not 2?

Also, we didn't add 'DataGrid1.Columns.Add 2' and it displayed all 8 columns with the format we set with your code.

Please explain.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41899947
There must be some other process going on that adds the columns. Perhaps the DataSource adds them.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:rayluvs
ID: 41899957
Yes! Right, we have Adodc 'dcRecs' in the form (see below)
dc
 dcRecs.ConnectionString = cnn
 dcRecs.RecordSource = sSql
 dcRecs.Refresh

Open in new window


Can you explain how it ?  (because when we right-click and 'retrieve fields' it doesn't show anything in the screen design but it does shows the columns in the RUN or when executed)
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41899961
Sorry, but I've never actually used a DataGrid.
0
 

Author Comment

by:rayluvs
ID: 41899966
Oh, thought u did since helping us; strange (but  thanx for it, it helped).
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41899993
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
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…

757 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

24 Experts available now in Live!

Get 1:1 Help Now