[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

06/19/2007 at 02:05AM PDT, ID: 22642587
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

VB6 listview dynamic filling columnheader formating and column sizing

Asked by DennisPost in VB Objects, Visual Basic Programming, VB Controls

Tags: listview, vb6

Hi,

I am trying to dynamically fill a listview in visual basic 6, and succeded.
There are 3 possible queries at the moment.
The idea is to set the listview column headers with the ado.rs.name then format the data depending on the column name and set the column widths according to datatypes.

So far the column headers and the values are correct, but i keeps formating the last columns incorrectly.

Here's my code. (The code I am having trouble with is marked by *****)
======================================================================================
Private Sub lvwStockTotals_DblClick()
On Error GoTo errorhandler

Dim str As String
    With lvwStockTotals
        .FullRowSelect = True
        str = .SelectedItem
    End With
   
    Me.lvwDetails.ListItems.Clear
    Me.lvwDetails.ColumnHeaders.Clear
    SQLrsFictStock = ""
   
   'Select the necessary query based on the selection in the first listview.
    If str = "In stock" Then
        Me.lblType = "In Stock"
        SQLrsFictStock = "SELECT C.Name Warehouse, Pcs, Colli, Kgs, Cbm, Plts FROM Stock S, Customers C WHERE S.WareID=C.CustID AND S.ArtID = " & Me.lblArtID
    ElseIf str = "Expected in" Then
        Me.lblType = "Expected In"
        SQLrsFictStock = "SELECT P.Name Pickup, I.PUDate Date, D.Name Delivery, I.DelDate Date, I.InOutID Reference, R.Pcs, R.Colli, R.Kgs, R.Cbm, R.Plts FROM [Rows] R, InOutHeaders I, Customers P, Customers D Where R.HeaderID = i.InOutID AND P.CustID=I.PUID AND D.CustID=I.DelID AND I.DirIN = 1 AND R.Confirmed = 0 AND ArtID = " & Me.lblArtID
    ElseIf str = "Reserved out" Then
        Me.lblType = "Reserved Out"
        SQLrsFictStock = "SELECT P.Name Pickup, I.PUDate Date, D.Name Delivery, I.DelDate Date, I.InOutID Reference, R.Pcs, R.Colli, R.Kgs, R.Cbm, R.Plts FROM [Rows] R, InOutHeaders I, Customers P, Customers D Where R.HeaderID = i.InOutID AND P.CustID=I.PUID AND D.CustID=I.DelID AND I.DirIN = 0 AND R.Confirmed = 0 AND ArtID = " & Me.lblArtID
    Else
        Exit Sub
    End If
   
    If OpenrsFictStock = True Then ' A function to open this specific recordset.
        If rsFictStock.BOF = False Then ' check that
            Dim i As Integer
            Dim j As Integer
            Dim k As Integer
            Dim RSF As Byte
           
            RSF = rsFictStock.Fields.Count - 1
            k = 1
           
            rsFictStock.MoveFirst
            'Headers & alignment
            For i = 0 To RSF
                'dynamically add the column headers
                Me.lvwDetails.ColumnHeaders.Add , , rsFictStock.Fields(i).Name
               
                'Align the columns and set the width based on the datatype
                If IsNumeric(rsFictStock.Fields(i).Value) Then
                    If i = 0 Then 'First column must always be aligned to the left
                        Me.lvwDetails.ColumnHeaders(i + 1).Alignment = lvwColumnLeft
                        Me.lvwDetails.ColumnHeaders(i + 1).Width = 2000
                    Else
                        Me.lvwDetails.ColumnHeaders(i + 1).Alignment = lvwColumnRight
                        Me.lvwDetails.ColumnHeaders(i + 1).Width = 1000
                    End If
                ElseIf IsDate(rsFictStock.Fields(i).Value) Then
                    Me.lvwDetails.ColumnHeaders(i + 1).Alignment = lvwColumnLeft
                    Me.lvwDetails.ColumnHeaders(i + 1).Width = 1000
                Else
                    Me.lvwDetails.ColumnHeaders(i + 1).Alignment = lvwColumnLeft
                    Me.lvwDetails.ColumnHeaders(i + 1).Width = 2000
                End If
            Next i
           
            rsFictStock.MoveFirst
            'Fill the rows
            Dim l As Integer
            l = 1
            Do While rsFictStock.EOF = False
                'Create the itemlists. Always the first of the rs selection list
                Me.lvwDetails.ListItems.Add , , rsFictStock.Fields(0).Value
               
                'Fill the rows of the listview column by column
                For j = 0 To RSF
***** This code doesn't format the columns correctly, though all the data is in the correct place.
'                    If IsDate(rsFictStock.Fields(j).Value) Then
'                        Me.lvwDetails.ListItems(k).SubItems(j) = Format(rsFictStock.Fields(j).Value, "DD-MM-YY")
'                    ElseIf Me.lvwDetails.ColumnHeaders(j) = "Cbm" Then
'                        Me.lvwDetails.ListItems(k).SubItems(j) = Format(rsFictStock.Fields(j).Value, "#.##0")
'                    ElseIf Me.lvwDetails.ColumnHeaders(j) = "Kgs" Then
'                        Me.lvwDetails.ListItems(k).SubItems(j) = Format(rsFictStock.Fields(j).Value, "Fixed")
'                    ElseIf Me.lvwDetails.ColumnHeaders(j) = "Plts" Then
'                        Me.lvwDetails.ListItems(k).SubItems(j) = Format(rsFictStock.Fields(j).Value, "Fixed")
'                    Else
'                        Me.lvwDetails.ListItems(k).SubItems(j) = rsFictStock.Fields(j).Value
'                    End If
                   
****** this code is simimar to the above code except I tried to use another integer variable to do the ******subitems                    
                    If Me.lvwDetails.ColumnHeaders(l) = "Date" Then
                        Me.lvwDetails.ListItems(k).SubItems(l) = Format(rsFictStock.Fields(j).Value, "DD-MM-YY")
                    ElseIf Me.lvwDetails.ColumnHeaders(l) = "Cbm" Then
                        Me.lvwDetails.ListItems(k).SubItems(l) = Format(rsFictStock.Fields(j).Value, "#.##0")
                    ElseIf Me.lvwDetails.ColumnHeaders(l) = "Kgs" Then
                        Me.lvwDetails.ListItems(k).SubItems(l) = Format(rsFictStock.Fields(j).Value, "Fixed")
                    ElseIf Me.lvwDetails.ColumnHeaders(l) = "Plts" Then
                        Me.lvwDetails.ListItems(k).SubItems(l) = Format(Null2Dbl(rsFictStock.Fields(j).Value), "Fixed")
                    Else
                        Me.lvwDetails.ListItems(k).SubItems(l) = rsFictStock.Fields(j).Value
                    End If
                    l = l + 1
                Next j
               
                k = k + 1
                rsFictStock.MoveNext
            Loop
           
            rsFictStock.Close
            Set rsFictStock = Nothing            
            AdoConn.Close 'Opened in the OpenrsFictStock function
            Set AdoConn = Nothing
        End If
       
        With Me.lvwDetails
            .HideColumnHeaders = False
            .View = lvwReport
        End With
    End If
               
Exit Sub
errorhandler:
    errore FrmFictStock, "lvwStockTotals, DblCick"
======================================================================================
[+][-]06/19/07 04:34 AM, ID: 19314795

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/19/07 05:20 AM, ID: 19315106

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/19/07 05:33 AM, ID: 19315187

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Objects, Visual Basic Programming, VB Controls
Tags: listview, vb6
Sign Up Now!
Solution Provided By: DennisPost
Participating Experts: 1
Solution Grade: B
 
 
[+][-]06/19/07 07:17 AM, ID: 19315996

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/20/07 06:03 AM, ID: 19324153

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06/20/07 07:40 AM, ID: 19324995

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91