[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......
Re: how to order liistview items by no. in the .ini?
You need a class for custom sorter, details and sample code is here
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.
Re: how to order liistview items by no. in the .ini?
Wait ... you mean you understood the question? :confused:
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.
Re: how to order liistview items by no. in the .ini?
Quote:
Originally Posted by
ident
I guessed ### is a new line, i also guessed Prog Name wants to be sorted by Install Order integer.
yea ur rite thx
Re: how to order liistview items by no. in the .ini?
Then answer my first question. Why are you using INI settings?
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......
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.........
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.
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...
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
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
Re: how to order liistview items by no. in the .ini?
No idea!
Is that error prevent running the program?
Re: how to order liistview items by no. in the .ini?
yea, won't let me debug.......
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)
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???
Re: how to order liistview items by no. in the .ini?
Quote:
Originally Posted by
chris-2k
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
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
do u no c# as a friend made a similiar app i have the code if u want???
I don't understand!
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:
Public Class Form1
Private Const SPLIT_DELIMITER As String = "##############################################################################"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim file As String = IO.File.ReadAllText("c:\SomeFile.ini")
Dim items() As String = file.Split(New String() {SPLIT_DELIMITER}, StringSplitOptions.RemoveEmptyEntries)
Dim collection = Populate(items)
Me.ListView1.Items.AddRange(
(
From line
In collection
Order By line.Order
Select New ListViewItem(line.Name)
).ToArray
)
End Sub
Private Shared Function Populate(ByVal items() As String) As List(Of Applications)
Return (From line In items
Let record = line.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
Select New Applications With {
.Order = Integer.Parse(record(0).Substring(record(0).Length - 1)),
.Name = record(1),
.Installer = record(2)
}).ToList()
End Function
Friend Structure Applications
Public Property Order As Integer
Public Property Name As String
Public Property Installer As String
End Structure
End Class
Re: [RESOLVED] how to order liistview items by no. in the .ini?
Have you decided to move to xml as this is sloppy?