How to retrieve several rows from database

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 978 Views - Last Post: 12 April 2013 - 05:04 AM Rate Topic: -----

#16 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to retrieve several rows from database

Posted 11 April 2013 - 05:25 PM

I'm pretty sure he understands, I think he's trying to make you understand. A list box is a, well, a box that contains a list. There's really no columnar format to it, it's a list. If you're wanting columns of rows, kind of like how you would view a spreadsheet, then you're probably wanting a listview or even better, a datagridview.

I guess, you could create a class that defines an object to hold the various columns of information for a row and add that object to the list with some kind of overrided toString function. So that you can extract the properties of said object when it's selected in the list. But when you are talking about a listbox and using terms like

Quote

Left hand side is for subject, middle is the sender, right is the date
it seems more sensible for you to be using some type of control that handles multiple columns easily.
Was This Post Helpful? 0
  • +
  • -

#17 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9286
  • View blog
  • Posts: 34,803
  • Joined: 12-June 08

Re: How to retrieve several rows from database

Posted 11 April 2013 - 08:18 PM

Yes.. I understand what you want to do.. you want a control that lists rows of data and have coherent columns of similar data. That is, quite precisely, a grid. Use. A. Grid.
Was This Post Helpful? 0
  • +
  • -

#18 StaticCrazee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 11-April 13

Re: How to retrieve several rows from database

Posted 12 April 2013 - 05:04 AM

Yes, I've searched around google and listview is what I needed! I've referred to this site for the tutorial and put the coedes into the program. Whenever I run the program from the debug folder send a message, it does not appear in the inbox and comes with the message,
"InvalidArgument=Value of '0' is not valid for 'index'
Parameter name:Index" If I press continue the program shows the inbox, but empty, with no messages, and if I press Quit, the program just exits. Help?

Private Sub Messages_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.Hide()
        Dim from As New TextBox
        Dim subject As New TextBox
        Dim ndate As New TextBox
        TextBox1.Enabled = False
        TextBox1.ReadOnly = True
        TextBox1.Text = UsersTableAdapter1.GetUsernameLoggedIn(True)
        Dim LView As New ListViewItem()
        Dim arr(3) As String
        Dim dateofmessage As Date = MessageTableAdapter1.GetDate(UsersTableAdapter1.GetID(True))
        Dim newdateofmessage As String = Format(dateofmessage, "ddMMYYYY")
        ListView1.Columns.Add("Subject", 100)
        ListView1.Columns.Add("Sender", 70)
        ListView1.Columns.Add("Date", 70)
        arr(0) = MessageTableAdapter1.GetTitle(UsersTableAdapter1.GetID(True))
        arr(1) = MessageTableAdapter1.GetSender(UsersTableAdapter1.GetID(True))
        arr(2) = newdateofmessage
        LView = New ListViewItem(arr)
        ListView1.Items.Add(LView)
        With ListView1.SelectedItems.Item(0)
            TextBox4.Text = arr(1)
            TextBox5.Text = UsersTableAdapter1.GetUsernameLoggedIn(True)
            TextBox6.Text = arr(0)
            RichTextBox2.Text = MessageTableAdapter1.GetMessage(TextBox6.Text, TextBox4.Text, UsersTableAdapter1.GetID(True))
            TextBox7.Text = arr(2)
            Panel1.Show()
        End With
    End Sub

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2