How to load unicode file into listview in VB.NET? 
Author Message
 How to load unicode file into listview in VB.NET?

How to load unicode file into listview in VB.NET?

I wanna load unicode .txt file into listview in VB.NET.
I use the following function (below) to load a delimited .txt file (unicode
UTF-8) into listview.
Problem is that data is not loaded as unicode, unicode characters are
represented with squares.
Why is that ? How to populate ListView with unicode representation of
characters?

I see that when I load text file (unicode UTF-8) to ListView and then save
that data to file, it saves OK, that is - in

unicode (although ListView shows squared characters at runtime). So I guess
that for some reason controls on Form

(ListView) at runtime misrepresent charachters.

(I'm developing on WinXP+VB.NET)

Public Sub LoadListView()
        On Error GoTo Err_Renamed 'Our error reporting
        'Our Variables

        Dim Fnum As Short 'For our FreeFile
        Dim tData As String 'Stores Data from a text file
        Dim tAry As Object 'Stores column items from text file
        Dim F As Short 'Used With our For Loop
        Const Delim As String = "<razmak>" 'Our unique delimiter. Feel free
To change this If needed. Just watch out

For what you use, it can cause problems.
        Dim Linija As Integer
        Linija = 0

        'Let's clear our ListView incase there is data already present
        ListView1.Items.Clear()

        'Let's get a free file handle
        Fnum = FreeFile()
        'Open our text file for inputing
        FileOpen(Fnum, FilePath, OpenMode.Input)
        'Do loop while were not at the End Of File

        Do While Not EOF(Fnum)
            'Input 1 line from our text file into the variable tData
            Input(Fnum, tData)
            'Split our line of text and store each indvidual value into an
array

            tAry = Split(tData, Delim)
            'Loop through each element of the array and add it to the
ListView

            If F = 0 Then
                'Add our item to the ListView

                ListView1.Items.Add("")  'ListView1.Items.Add("", 1) <- this
1 is for icon index

                ListView1.Items(Linija).SubItems.Add(Linija + 1) 'this is
subitem 1
                ListView1.Items(Linija).SubItems.Add(tAry(1)) 'this is
subitem 2
                ListView1.Items(Linija).SubItems.Add(tAry(2)) 'this is
subitem 3
                ListView1.Items(Linija).SubItems.Add(tAry(3)) 'this is
subitem 4
                Linija = Linija + 1

            End If

        Loop  'Continue on
        FileClose(Fnum) 'Close our file

        StatusBar1.Panels(1).Text = "Total lines: " & ListView1.Items.Count

        Exit Sub 'Exit this sub
Err_Renamed:  ' Our Error reporting. Feel free To fix this up
        MsgBox("Error Loading Data File.", MsgBoxStyle.Critical)
    End Sub



Mon, 12 Sep 2005 08:45:55 GMT  
 How to load unicode file into listview in VB.NET?
Hallo,


Quote:
> I use the following function (below) to load a delimited .txt file
(unicode
> UTF-8) into listview.

Are you sure the characters are loaded in UTF-8 mode?

\\\
Imports System.IO
Imports System.Text

Public Module Module1
    Public Sub Main()
        Dim s As Stream = _
            New FileStream( _
                "C:\WINDOWS\ODBCINST.INI", _
                FileMode.Open _
            )
        Dim tr As StreamReader = _
            New StreamReader(s, Encoding.UTF8)
        Dim str As String
        Do While tr.Peek > -1
            str = tr.ReadLine()
            Console.WriteLine(str)
        Loop
        Console.ReadLine()
    End Sub
End Module
///

Regards,
Herfried K. Wagner



Mon, 12 Sep 2005 09:47:39 GMT  
 How to load unicode file into listview in VB.NET?
thanx, this helps!
Quote:
----- Original Message -----

> \\\
> Imports System.IO
> Imports System.Text

> Public Module Module1
>     Public Sub Main()
>         Dim s As Stream = _
>             New FileStream( _
>                 "C:\WINDOWS\ODBCINST.INI", _
>                 FileMode.Open _
>             )
>         Dim tr As StreamReader = _
>             New StreamReader(s, Encoding.UTF8)
>         Dim str As String
>         Do While tr.Peek > -1
>             str = tr.ReadLine()
>             Console.WriteLine(str)
>         Loop
>         Console.ReadLine()
>     End Sub
> End Module
> ///

> Regards,
> Herfried K. Wagner



Mon, 12 Sep 2005 12:05:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Slow loading of VB .Net exe file

2. Loading HELP File in VB .NET

3. displaying unicode characters in vb controls like ListView

4. Loading a pop-up window on startup in VB.NET AND ASP.NET

5. How to convert the text from unicode to big5 format in vb.net

6. Scripting unicode & non-unicode text files

7. Load a file into LISTVIEW box

8. Load a listview with files from a dir

9. unicode charactrer handling in files in VB

10. VB.NET app does not run on OS having .NET redistributable files installed

11. File Versioning in VS.NET/VB.NET

12. UNICODE display in ListView

 

 
Powered by phpBB® Forum Software