Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Custom populate ListView from mySQL DB

Posted on 2005-05-13
6
Medium Priority
?
343 Views
Last Modified: 2008-02-01
Hello!

I am trying to do a custom Listview Population code.

I am using a setting.ini file to set the names of the columnheaders and I need to also set in the ini file what fieldnames to go with those
columnheaders.
Column headers is very easy:

        For ggr = 1 To ReadINI("Datagrid", "headers", App.Path + "\settings.ini")
            lvRecs.ColumnHeaders.Add ggr, , ReadINI("Datagrid", CStr(ggr), App.Path + "\settings.ini")
        Next

this populates the colimn headers on the ListView.

I want to now :

How do I automate the:
lvRecs.ListItems.Add , , Str(rsClients.Fields!UserId)  <-

so when adding another field in the database, all I have to do is alter the settings.ini with the new field.

Using a datagrid would solve the problem but adodc and datagrid are way to buggy for me,
they work and crash now and then so they are not reliable at all.

Alternatively, do you know another listview/datagrid/something that works better than adodc+datagrid.

/BK
0
Comment
Question by:Berhan Karagoez
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
Preece earned 1500 total points
ID: 13999861
You might consider using an MSFlexGrid control.  Here is some sample code to setup and populate a flexgrid:

grdParts.cols = 4
    grdParts.ColAlignment(1) = flexAlignLeftCenter
    grdParts.ColAlignment(2) = flexAlignLeftCenter
    'grdParts.ColAlignment(2) = flexAlignLeftCenter
    grdParts.ColAlignment(3) = flexAlignRightCenter
    grdParts.ColWidth(0) = 0
    grdParts.ColWidth(1) = 1000
    grdParts.ColWidth(2) = 4500
    grdParts.ColWidth(3) = 1000
   
    grdParts.Row = 0
    grdParts.Col = 1
    grdParts.Text = "Part Num"
    grdParts.Col = 2
    grdParts.Text = "Description"
    grdParts.Col = 3
    grdParts.Text = "MSRP"
   
    ' populate default first row
    grdParts.Row = 1
    grdParts.Col = 1
    grdParts.Text = "2871217"
    grdParts.Col = 2
    grdParts.Text = "Gen III Mirror"
    grdParts.Col = 3
    grdParts.Text = "$34.99"

    ' add new rows
    grdParts.AddItem vbTab & "2872702" & vbTab & "ROCK GUARD,GEN III" & vbTab & "$24.99"
    grdParts.AddItem vbTab & "2872323" & vbTab & "1999-2004 Scrambler 500 electronic speedometer" & vbTab & "$229.99"
    grdParts.AddItem vbTab & "2872699" & vbTab & "Alum A-Arm guards" & vbTab & "$119.99"
    grdParts.AddItem vbTab & "2872698" & vbTab & "Alum full chassis skid plate" & vbTab & "$99.99"
    grdParts.AddItem vbTab & "2872701" & vbTab & "Alum swing arm guard" & vbTab & "$99.99"
    grdParts.AddItem vbTab & "2871792" & vbTab & "Shock covers - front" & vbTab & "$29.99"
    grdParts.AddItem vbTab & "2873052" & vbTab & "Shock covers - rear" & vbTab & "$14.99"
    grdParts.AddItem vbTab & "2873946" & vbTab & "Gen III alum front bumper" & vbTab & "$199.99"
    grdParts.AddItem vbTab & "2872043" & vbTab & "Gen III front rack" & vbTab & "$79.99"
    grdParts.AddItem vbTab & "2872044" & vbTab & "Gen III rear rack" & vbTab & "$119.99"
    grdParts.AddItem vbTab & "2872342" & vbTab & "Gen III Black Front Rack Bag" & vbTab & "$49.99"
    grdParts.AddItem vbTab & "2872343" & vbTab & "Gen III Black Rear Rack Bag" & vbTab & "$49.99"
    grdParts.AddItem vbTab & "2873559" & vbTab & "Gen III ATV cover" & vbTab & "$69.99"
    grdParts.AddItem vbTab & "2873341" & vbTab & "Gen III Cooler / gas rack bag" & vbTab & "$44.99"
    grdParts.AddItem vbTab & "2872045" & vbTab & "Gen III Gas can rack" & vbTab & "$74.99"
    grdParts.AddItem vbTab & "2873559" & vbTab & "Gen III Cover Black/Red" & vbTab & "$69.99"
    grdParts.AddItem vbTab & "2872339" & vbTab & "Gen III Black Tank Saddle Bags" & vbTab & "$49.99"
    grdParts.AddItem vbTab & "2873555" & vbTab & "Gen III Screen Headlight Cover" & vbTab & "$24.99"
   

Now, in this example, I've hard-coded the values, but you can easily use a recorset instead.
0
 
LVL 12

Expert Comment

by:Preece
ID: 13999949
Notice I've set the first "header" column to a width of 0:

grdParts.ColWidth(0) = 0

And I'm setting the header row values, which you can do with your calls to the ini

Regarding to the part of populating data, you could build a string, such as:

sData =  vbTab & rsClients.Fields!UserId & vbTab & rsClients.Fields!UserName & vbTab & rsClients.Fields!UserPhone

Then use it to add to the grid:
grdParts.AddItem sData

0
 

Author Comment

by:Berhan Karagoez
ID: 13999990
Preece, thanx for the answer but this is not what I am looking for.

The code should be in a for..next ro loop to read all fields from the settings ini. the whole point with this question is not to what you show.

/BK
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Berhan Karagoez
ID: 13999999
Also the data is retrieved from a database, this is the "tricky part".
How do I from what I have in the settings file (field names) populate the drid/LV with right field data.

/BK
0
 
LVL 12

Expert Comment

by:Preece
ID: 14000089
Yeah, the code was intended to give you an idea of how to use a FlexGrid.  It is up to you to adapt it to your getting of a recordset, using the for loop, etc.  Because I'm not there, an I can only provide guidance based upon the little bit of info you've provided.  I'm not grilling you, I'm just making a point!

But to your point of getting the field names to synch up with the grid, here are some things to ponder:

Read in your ini file, put the field names into a collection or an array, then use that collection / array to:

- setup up your grid
- get your rs
- populate your grid

This is assuming that the order of your field names in the ini is the order in which you want the data to be displayed in the grid...

I like the idea of adding a field to ini and then the code dynamically adding a new column and the respective data to the grid.  Saves adding code and recompiling...

Preece
0
 

Author Comment

by:Berhan Karagoez
ID: 14003410
Yes, the whole idea is to do just that.

Let' me test your suggestion, and get back to you!

/BK
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

580 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