I have a database with 3 columns, and approx 60 rows

I need to load this into vb6, into a listbox or what ever you think will work best, in the listbox (or???) I will need the 3 columns, plus a fouth column(at the beginning) that has check boxes.

Can some one point me in the right direction to do this?

Dani AI

Generated

For : the simplest, most maintainable route is a ListView in Report view. As suggested, that gives you column headers and a checkbox per row; was right to suggest a grid if you only need tabular display, but grids (MSFlexGrid/DataGrid) do not provide an easy native per‑row checkbox like ListView does.

Workflow to follow:

  1. Put a ListView on the form, set View to Report and enable the control's Checkboxes property in the Properties window.
  2. Add three column headers (PID, Acronym, Description).
  3. Use ADO to open your Access table and loop the recordset, adding a ListItem for each row and filling SubItems for the other two columns.

Example VB6 snippet (replace path/table names as needed):

' Requires a reference to Microsoft ActiveX Data Objects 2.x
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\path\pids.mdb;"
Set rs = New ADODB.Recordset
rs.Open "SELECT PID, Acronym, Description FROM standard_pids", cn, adOpenForwardOnly, adLockReadOnly

Dim li As ListItem
Do While Not rs.EOF
    Set li = ListView1.ListItems.Add(, , rs!PID)
    li.SubItems(1) = rs!Acronym
    li.SubItems(2) = rs!Description
    rs.MoveNext
Loop

rs.Close
cn.Close

Quick troubleshooting: ensure mscomctl.ocx is registered and the ADO reference is set. For .accdb use the ACE provider. If performance becomes an issue with thousands of rows, consider paging, a virtual list, or binding a DataGrid instead.

Recommended Answers

All 6 Replies

Pllease specify your requirment clearly.
Do u want to load the data of all the three columns into a single listbox.
or you want only to display the records, in that case u can use any grid control.

I have a database called pids
a table called standard_pids
three colums PID/Acronym/Description
I need all three loaded in a listbox? but I will also require a fourth row at the beginning with CheckBoxes

Can anyone point me in correct direction?

Hi,

use a listView or a MSFlexGrid Control..

Regards
Veena

Thank you for your reply, I have a listview, but how do I get checkboxes in first row? or do i do that in MS Access first?

Hi,

Set this property:

lvw.Checkboxes = True

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.