3 Replies - 34554 Views - Last Post: 25 May 2013 - 04:37 AM Rate Topic: -----

#1 ShawnaInMaine   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 05-May 11

Adding items to listview.

Posted 24 May 2013 - 09:44 AM

Okay I am trying to show the entrys entered into the textboxes in a listview.

    Sub listingarea()

     

            'this will add items to list view.
            resultlist.Items.Add(ApplianceCombo.SelectedItem)
            resultlist.Items(0).SubItems.Add(CostPerKilo.Text)
            resultlist.Items(0).SubItems.Add(PowerNeeded.Text)
            resultlist.Items(0).SubItems.Add(HoursperDay.Text)
            resultlist.Items(0).SubItems.Add(Format$(total, "Currency"))


    End Sub


    Private Sub addtolist_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles addtolist.Click
        Call listingarea()
    End Sub




When the button is clicked the first time it adds the entry, however when I change the input and click the button again it only adds the selection from appliance combo. Would I need to use a loop to continue entering data from textboxes when they are changed?

On LoadPosted Image



First time button is pushed
Posted Image


Pushed button few more times while changing dataPosted Image

This post has been edited by ShawnaInMaine: 24 May 2013 - 09:46 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Adding items to listview.

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,311
  • Joined: 12-December 12

Re: Adding items to listview.

Posted 24 May 2013 - 10:13 AM

This fails because you are constantly referring to the first row (0), but you should also create and add a ListViewItem:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim newItem As New ListViewItem(TextBox1.Text)
        newItem.SubItems.Add(TextBox2.Text)
        newItem.SubItems.Add(TextBox3.Text)
        ListView1.Items.Add(newItem)
    End Sub

Was This Post Helpful? 0
  • +
  • -

#3 ShawnaInMaine   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 05-May 11

Re: Adding items to listview.

Posted 24 May 2013 - 07:19 PM

View Postandrewsw, on 24 May 2013 - 10:13 AM, said:

This fails because you are constantly referring to the first row (0), but you should also create and add a ListViewItem:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim newItem As New ListViewItem(TextBox1.Text)
        newItem.SubItems.Add(TextBox2.Text)
        newItem.SubItems.Add(TextBox3.Text)
        ListView1.Items.Add(newItem)
    End Sub



Okay if I use this, what happens to the other text box info? I tried implementing it however I still get the same results only the new item skips a line

Sub listingarea()

     

        'this will add items to list view.
        Dim newItem As New ListViewItem
            resultlist.Items.Add(ApplianceCombo.SelectedItem)
            resultlist.Items(0).SubItems.Add(CostPerKilo.Text)
            resultlist.Items(0).SubItems.Add(PowerNeeded.Text)
            resultlist.Items(0).SubItems.Add(HoursperDay.Text)
            resultlist.Items(0).SubItems.Add(Format$(total, "Currency"))
        resultlist.Items.Add(newItem)

    End Sub



Posted Image
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry   User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: Adding items to listview.

Posted 25 May 2013 - 04:37 AM

View PostShawnaInMaine, on 24 May 2013 - 08:19 PM, said:

View Postandrewsw, on 24 May 2013 - 10:13 AM, said:

This fails because you are constantly referring to the first row (0), but you should also create and add a ListViewItem:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim newItem As New ListViewItem(TextBox1.Text)
        newItem.SubItems.Add(TextBox2.Text)
        newItem.SubItems.Add(TextBox3.Text)
        ListView1.Items.Add(newItem)
    End Sub



Okay if I use this, what happens to the other text box info? I tried implementing it however I still get the same results only the new item skips a line

andrewsw has supplied you with an example that you need to modify to place into your code. You have only used the first and last lines, and left the other lines the same. In particular, you are still using (0), which is referring to the first row. The example code supplied builds a single ListViewItem from three TextBoxes, then adds it to the ListView.

To successfuly use the technique, replace your code inside listingarea () with the code supplied, changing TextBox and ListView names to your own names.
You will also need to add your other inputs in the same manner.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1