Link to home
Start Free TrialLog in
Avatar of jana
janaFlag for United States of America

asked on

Add and format columns in vb6

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.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

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.
There must be some other process going on that adds the columns. Perhaps the DataSource adds them.
Avatar of jana

ASKER

Yes! Right, we have Adodc 'dcRecs' in the form (see below)
User generated image
 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)
Sorry, but I've never actually used a DataGrid.
Avatar of jana

ASKER

Oh, thought u did since helping us; strange (but  thanx for it, it helped).
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