Results 1 to 3 of 3

Thread: [RESOLVED] Populating textfields with data from listview

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Resolved [RESOLVED] Populating textfields with data from listview

    So I have been searching for a while now with no luck.

    What I want to do is gather the data that displays in my listview (called 'lstData') when selected and populate my textfields with it's information.
    Pretty simple, I know. =S

    Here's the rub.

    SelectedItem, SelectedIndex, etc... any of these selected variations aren't working for me. I get this error message "'SelectedIndex' is not a member of 'System.Windows.Forms.ListView'".

    Database: Sql Server

    Here is my code, hopefully someone can see what I have done wrong?

    Private Sub lstData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstData.SelectedIndexChanged

    'declare myCourse variable
    Dim myCourse As New Courses
    'populate myCourse with selected item
    myCourse = lstData.SelectedItems

    'set variables
    txtId.Text = myCourse.id
    txtName.Text = myCourse.name
    txtAbbrev.Text = myCourse.abbrev
    dtpStart.Value = myCourse.sdate
    dtpExpiry.Value = myCourse.edate
    txtInstructor.Text = myCourse.instr
    cbType.SelectedItem = myCourse.type
    txtCost.Text = myCourse.cost
    txtCompany.Text = myCourse.comp
    rtxtDetails.Text = myCourse.details
    txtTime.Text = myCourse.time

    'id textfield is now viewable
    txtId.Visible = True
    'makes it so that you cannot update course's ID when selected in list box.
    txtId.Enabled = False
    End Sub

    I feel as though I've exhausted every option.

    Any ideas would be greatly appreciated. Thanks guys!

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Re: Populating textfields with data from listview

    Sorry, selecteditems.. selectedindex... either way I go I get the same error message just a different selection type.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Thumbs up Re: Populating textfields with data from listview

    So I ended up figuring out what was wrong...

    I was using a ListBox when I should have been using a ListView. I must have accidentally dragged the wrong one over when creating my GUI.

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