Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Visual Basic problem  (Read 3399 times)

0 Members and 1 Guest are viewing this topic.

alecsillidan

    Topic Starter


    Beginner

    Visual Basic problem
    « on: November 11, 2011, 10:24:18 AM »
    Hi, I'm using visual basic with .net framework 4, and I made a program that gets the strings from a table in a database and shows them in a listbox, the listbox shows the elements correctly, but when i try to set a variable with the index string (Label1.Text = listbox1.selecteditem() ) I get System.Data.DataRow or something like that, i want to get the string. Can someone help me?
    Thank you.
    We never had to cheat 'cause we already won!

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Visual Basic problem
    « Reply #1 on: November 11, 2011, 01:13:16 PM »
    listbox1.selecteditem().ToString()

    OR get the actual field you want from the DataRow.
    I was trying to dereference Null Pointers before it was cool.

    alecsillidan

      Topic Starter


      Beginner

      Re: Visual Basic problem
      « Reply #2 on: November 11, 2011, 04:13:46 PM »
      Label1.Text = ListBox1.SelectedItem().ToString() not working
      I get the text "System.Data.DataRowView" instead of the actual string in the DB
      We never had to cheat 'cause we already won!

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Visual Basic problem
      « Reply #3 on: November 11, 2011, 05:29:20 PM »
      Label1.Text = ListBox1.SelectedItem().ToString() not working
      I get the text "System.Data.DataRowView" instead of the actual string in the DB

      You'll need to get the field from the DataRow, then.

      Code: [Select]
      ListBox1.SelectedItem("fieldname").ToString()
      I was trying to dereference Null Pointers before it was cool.

      alecsillidan

        Topic Starter


        Beginner

        Re: Visual Basic problem
        « Reply #4 on: November 12, 2011, 12:26:04 PM »
        It works fine, thank you for helping me.
        Solved.
        We never had to cheat 'cause we already won!