Results 1 to 20 of 20

Thread: [RESOLVED] how to order liistview items by no. in the .ini?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Resolved [RESOLVED] how to order liistview items by no. in the .ini?

    `Exachtly the question: "how to order liistview items by no. in the .ini?"

    the .ini file:
    Code:
    Install Order:1
    Prog Name:Adobe Reader X 11.0.02
    Installer File:Install\Apps\AcroRdrX-11.0.02.exe
    
    ##############################################################################
    
    Install Order:2
    Prog Name:Adobe Photoshop CS5 Extended Edition
    Installer File:Install\Apps\Adobe_Photoshop_CS5_Extended_Edition_Silent_Chris2k.exe
    
    ##############################################################################
    
    Install Order:3
    Prog Name:Adobe Dreamweaver CS5 Lite Edition
    Installer File:Install\Apps\Adobe_Dreamweaver_CS5_Lite_Edition_Silent_Chris2k.exe
    
    ##############################################################################
    
    Install Order:4
    Prog Name:AVG Antivirus 2013.0.2805
    Installer File:Install\Apps\AVG_Antivirus_2013.0.2805_Silent_Chris2k.exe
    my code:
    Code:
            Dim installOrder As Integer = 0
            Dim highestOrder As Integer = 1
    
            For Each ln In IO.File.ReadAllLines(iniFile)
                If ln.ToLower.StartsWith("install order") Then
                    installOrder = (ln.Substring(ln.IndexOf(":"c) + 1)) ' a faster and more efficient option than splitting
                    App_List.Items.Add(installOrder)
                ElseIf ln.ToLower.StartsWith("app name") Then
                    Dim app_name As String = (ln.Substring(ln.IndexOf(":"c) + 1))
                    App_List.Items(1).SubItems.Add(app_name)
                ElseIf ln.ToLower.StartsWith("description") Then
                    Dim app_desc As String = (ln.Substring(ln.IndexOf(":"c) + 1))
                    App_List.Items(2).SubItems.Add(app_desc)
                ElseIf ln.ToLower.StartsWith("app file size") Then
                    Dim app_filesize As String = (ln.Substring(ln.IndexOf(":"c) + 1))
                    App_List.Items(3).SubItems.Add(app_filesize)
                ElseIf ln.ToLower.StartsWith("app file") Then
                    Dim exe_path As String = (ln.Substring(ln.IndexOf(":"c) + 1))
                    App_List.Items(4).SubItems.Add(exe_path)
                End If
            Next
    I have no idea......

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: how to order liistview items by no. in the .ini?

    You need a class for custom sorter, details and sample code is here



  3. #3
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: how to order liistview items by no. in the .ini?

    Is there a particular reason for not using XML? Would be a lot easier.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: how to order liistview items by no. in the .ini?

    Wait ... you mean you understood the question?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: how to order liistview items by no. in the .ini?

    I guessed ### is a new line, i also guessed Prog Name wants to be sorted by Install Order integer.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: how to order liistview items by no. in the .ini?

    Quote Originally Posted by ident View Post
    I guessed ### is a new line, i also guessed Prog Name wants to be sorted by Install Order integer.

    yea ur rite thx

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: how to order liistview items by no. in the .ini?

    Then answer my first question. Why are you using INI settings?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: how to order liistview items by no. in the .ini?

    Ident or dun, from the link given, how can i implement to my code......

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: how to order liistview items by no. in the .ini?

    because i find it easier to write and read a .ini file, maybe xml is easier.........

  10. #10
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: how to order liistview items by no. in the .ini?

    What do you mean by "how to order"? I have understood it as "how to sort" am i correct?

    After reviewing your code, i don't think it is populate the listview with the data in the ini file properly, so please describe your problem more clearly.



  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: how to order liistview items by no. in the .ini?

    First off, thanks for ur time..

    I'll try,

    Ok I want my apps to be in numeric order, by the install order from my .ini file, like:

    1... im 1st
    2... im 2nd
    3... im 3rd
    9... im 4th as theres no 4,5,6,7,8 etc...

  12. #12
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: how to order liistview items by no. in the .ini?

    To sort the listview, add a new class to the project and name it ListViewItemComparer (or any other name of your choice) then paste the following code inside it
    Code:
    Public Class ListViewItemComparer
        Implements IComparer
    
        Private mintColumn As Integer
        Private mblnAscending As Boolean
    
        Public Sub New()
            mintColumn = 0
            mblnAscending = True
        End Sub
    
        Public Sub New(ByVal intColumn As Integer, ByVal blnAscending As Boolean)
            mintColumn = intColumn
            mblnAscending = blnAscending
        End Sub
    
        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
            Dim ix As ListViewItem = DirectCast(x, ListViewItem)
            Dim iy As ListViewItem = DirectCast(y, ListViewItem)
    
            If mblnAscending = True Then
                Return String.Compare(ix.SubItems(mintColumn).Text, iy.SubItems(mintColumn).Text)
            Else
                Return String.Compare(iy.SubItems(mintColumn).Text, ix.SubItems(mintColumn).Text)
            End If
        End Function
    in your main form use the following code for the event App_List.ColumnClick
    Code:
        Private Sub App_List_ColumnClick(sender As Object, e As ColumnClickEventArgs) Handles App_List.ColumnClick
            ' Remove sort indicator
            For Each lvcColumn As ColumnHeader In App_List.Columns
                If lvcColumn.Text.StartsWith("+ ") OrElse lvcColumn.Text.StartsWith("- ") Then
                    lvcColumn.Text = lvcColumn.Text.Substring(2)
                End If
            Next
    
    
            Static blnSortAscending As Boolean
    
            blnSortAscending = Not blnSortAscending
            App_List.ListViewItemSorter = New ListViewItemComparer(e.Column, blnSortAscending)
            App_List.Columns(e.Column).Text = If(blnSortAscending = True, "+ ", "- ") & App_List.Columns(e.Column).Text
    
        End Sub
    Last edited by 4x2y; May 22nd, 2013 at 08:36 AM.



  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: how to order liistview items by no. in the .ini?

    thank u very much...

    hmmmmm when i added the class, i get this error: Error 1 Too few type arguments to 'System.Collections.Generic.IComparer(Of T)'. H:\X17-59183\PostInstall\PostInstall\ListViewItemComparer.vb 2 20 PostInstall

  14. #14
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: how to order liistview items by no. in the .ini?

    No idea!

    Is that error prevent running the program?



  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: how to order liistview items by no. in the .ini?

    yea, won't let me debug.......

  16. #16
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: how to order liistview items by no. in the .ini?

    What's the line the debugger stop when you start?

    Maybe there is a conflict with other parts, try to test my code in a new project (just add a listview and fill it manually with some items)



  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: how to order liistview items by no. in the .ini?

    Hi, i done that, works fine, it's not ordering by number, i did 1,3,5,7,2,4,6,8 as items in that order, then i debug it, they stay as is...

    my current SLN is set for .net fr 2.0, maybe a problem?

    do u no c# as a friend made a similiar app i have the code if u want???

  18. #18
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: how to order liistview items by no. in the .ini?

    Quote Originally Posted by chris-2k View Post
    Hi, i done that, works fine, it's not ordering by number, i did 1,3,5,7,2,4,6,8 as items in that order, then i debug it, they stay as is...
    You said "works fine" then "they stay as is..." how comes?

    if you want to sort numerically not alphabetically, that is, 10,11 ... not comes after 1 and before 2 then use the following comparer:

    Code:
    Option Strict On
    Option Explicit On
    
    Public Class ListViewNumericallySorter
        Implements IComparer
    
        Private mintColumn As Integer
        Private mblnAscending As Boolean
    
        Public Sub New()
            mintColumn = 0
            mblnAscending = True
        End Sub
    
        Public Sub New(ByVal intColumn As Integer, ByVal blnAscending As Boolean)
            mintColumn = intColumn
            mblnAscending = blnAscending
        End Sub
    
        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
    
            Dim ix As ListViewItem = DirectCast(x, ListViewItem)
            Dim iy As ListViewItem = DirectCast(y, ListViewItem)
            Dim intX As Integer
            Dim intY As Integer
    
            Integer.TryParse(ix.SubItems(mintColumn).Text, intX)
            Integer.TryParse(iy.SubItems(mintColumn).Text, intY)
    
            If mblnAscending = True Then
                Return intX.CompareTo(intY)
            Else
                Return intY.CompareTo(intX)
            End If
    
        End Function
    End Class
    Quote Originally Posted by chris-2k View Post
    my current SLN is set for .net fr 2.0, maybe a problem?
    I don't think so because i have changed my test project to target framework 2.0 and it is still works fine

    Quote Originally Posted by chris-2k View Post
    do u no c# as a friend made a similiar app i have the code if u want???
    I don't understand!
    Last edited by 4x2y; May 22nd, 2013 at 02:18 PM.



  19. #19
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: how to order liistview items by no. in the .ini?

    I have not read the rest of this thread so forgive me if updated. I also have never done any work with INI files. The code i have just written feels like a textfile split into strings hiding as a ini file. Surely the frame work has an old ini class? I seriously suggest moving to xml

    maybe some thing like

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Const SPLIT_DELIMITER As String = "##############################################################################"
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.  
    7.         Dim file As String = IO.File.ReadAllText("c:\SomeFile.ini")
    8.         Dim items() As String = file.Split(New String() {SPLIT_DELIMITER}, StringSplitOptions.RemoveEmptyEntries)
    9.         Dim collection = Populate(items)
    10.  
    11.         Me.ListView1.Items.AddRange(
    12.                                     (
    13.                                         From line
    14.                                         In collection
    15.                                         Order By line.Order
    16.                                         Select New ListViewItem(line.Name)
    17.                                     ).ToArray
    18.                                    )
    19.     End Sub
    20.  
    21.  
    22.     Private Shared Function Populate(ByVal items() As String) As List(Of Applications)
    23.         Return (From line In items
    24.                Let record = line.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
    25.                Select New Applications With {
    26.                    .Order = Integer.Parse(record(0).Substring(record(0).Length - 1)),
    27.                    .Name = record(1),
    28.                    .Installer = record(2)
    29.                }).ToList()
    30.     End Function
    31.  
    32.     Friend Structure Applications
    33.         Public Property Order As Integer
    34.         Public Property Name As String
    35.         Public Property Installer As String
    36.     End Structure
    37. End Class

  20. #20
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [RESOLVED] how to order liistview items by no. in the .ini?

    Have you decided to move to xml as this is sloppy?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width