?
Solved

Add and format columns in vb6

Posted on 2016-11-23
7
Medium Priority
?
102 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
[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
  • 4
  • 3
7 Comments
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 49

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 49

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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
Course of the Month10 days, 23 hours left to enroll

770 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