none
Vb.net listview items.add help

    Question

  • Hi!

    Got a problem!

    I got a textbox with lets say 3 rows of text

    1.Hello

    2.My name is

    3.Simon

     

    And i got a listview that is on detailed

    When i press a button: for each row listview item add.

    So the listview items will be 3 items, 1 item per row in the textbox thats on multiline.

     

    Thanks!


    If you don´t Believe in it, Then it Doesn´t Exist!
    Tuesday, May 25, 2010 3:13 PM

Answers

All replies

  • try this:
    for each line as string in textbox1.lines
     listview1.items.add(line)
    next
    
    • Proposed as answer by .paul. _ Tuesday, May 25, 2010 3:24 PM
    Tuesday, May 25, 2010 3:23 PM
  • There is lines property for textbox, so loop through the textbox lines and add it to your listview,below is a sample code that will give you an idea

    For i as Integer=0 to Textbox1.Lines.Lenght-1

    ListView1.Item.Add(Textbox1.Lines(i))


    Next


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    Tuesday, May 25, 2010 3:25 PM
  • I used this code to read from a txt file

     

    Dim fileReader As String
                fileReader = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
            
                Dim txtLines As String() = fileReader.Split(Environment.NewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries)

    then how to add each line into many items?


    If you don´t Believe in it, Then it Doesn´t Exist!
    Tuesday, May 25, 2010 5:55 PM
  • Did you ever learn anything from this forum ? at least you should be able to adapt the method posted by bibliophage to do this. All you have to do is to loop through the string array

    For each itm as string in txtLines

    ListView1.Item.Add(itm)

    Next

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Marked as answer by Simon PH3K Tuesday, May 25, 2010 6:14 PM
    Tuesday, May 25, 2010 6:08 PM
  • Thx!

    Ofc ive learn'd alot of thing from you nice guys!


    If you don´t Believe in it, Then it Doesn´t Exist!
    Tuesday, May 25, 2010 6:14 PM
  • assuming you're using vb2008 or vb2010, you could use LINQ:

     

    Dim items = (From line In IO.File.ReadAllLines(OpenFileDialog1.FileName) _
           Select New ListViewItem(line)).toarray
    listview1.items.addrange(items)
    • Proposed as answer by .paul. _ Tuesday, May 25, 2010 6:34 PM
    Tuesday, May 25, 2010 6:34 PM