Results 1 to 9 of 9

Thread: ListBox Question

  1. #1

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36

    ListBox Question

    Ok I have my customers set up in SQL and I want to display the AccountNumber, FirstName, LastName, AccountStatus, and AccountBalance.

    First off is this even possible to do? Second can i set it up so that when I click the header can I have it sort by column? And last how do I do it?

    Thanks in Advanced

    Brad Nichols
    Last edited by jnichols; May 22nd, 2004 at 12:14 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    * bump *

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    You have probably not received a prompt response because the width of your question makes it difficult to know where to begin. Your posted heading refers to List Boxes. Does that mean you want to display all the information in a listbox?

    Do you know how to get the information from the database into a datatable or a dataset?

    I'm not too sure what you mean by "can i set it up so that when I click the header can I have it sort by column?" Are you confusing this with the Database ability to do it?

    Finally, is it possible that you are thinking of VB Scripting rather than VB.NET?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    Maybe I didn't explain it correctly

    What I want to be able to do is click on Customer List from my Main Menu and open another form with a ListBox displaying all the above information from the customer table in the database. I have know idea how to retrieve the data and display it this way. A program that has something like this is Quickbooks. When you click on customer list it displays a listing of all the customers. Please let me know if this is enough info about what I am trying to do.

    Brad Nichols

  5. #5

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    WindowsApplication23 is very close to what i am looking for. But see attachment. And see if I can do something like this.
    Attached Images Attached Images  
    Last edited by jnichols; May 23rd, 2004 at 10:29 PM.

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    You have probably already noticed it but look at thread

    http://www.vbforums.com/showthread.p...hreadid=291093
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    ayan can you repost WindowsApplication23 the one posted is corupt. I d/l it yesterday but can't today. Thanks

  8. #8
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    here it is j... glad to repost this...
    Attached Files Attached Files

  9. #9

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    I don't know but this is what i've got so far. Is there anyway to select the whole record not just the first column? As you may notice there is a textbox on top of the listview which I would like to be able to start typing a name and it automatically select it??

    Also is it possible to do this in a listbox or is listview the way to go? And finally can the columns be sorted?

    VB Code:
    1. Imports System.Data.SqlClient
    2. Public Class frmCustomerList
    3.     Inherits System.Windows.Forms.Form
    4.  
    5. #Region " Windows Form Designer generated code "
    6.  
    7.     Public Sub New()
    8.         MyBase.New()
    9.  
    10.         'This call is required by the Windows Form Designer.
    11.         InitializeComponent()
    12.  
    13.         'Add any initialization after the InitializeComponent() call
    14.  
    15.     End Sub
    16.  
    17.     'Form overrides dispose to clean up the component list.
    18.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    19.         If disposing Then
    20.             If Not (components Is Nothing) Then
    21.                 components.Dispose()
    22.             End If
    23.         End If
    24.         MyBase.Dispose(disposing)
    25.     End Sub
    26.  
    27.     'Required by the Windows Form Designer
    28.     Private components As System.ComponentModel.IContainer
    29.  
    30.     'NOTE: The following procedure is required by the Windows Form Designer
    31.     'It can be modified using the Windows Form Designer.  
    32.     'Do not modify it using the code editor.
    33.     Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    34.     Friend WithEvents Label1 As System.Windows.Forms.Label
    35.     Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
    36.     Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
    37.     Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
    38.     Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
    39.     Friend WithEvents ColumnHeader5 As System.Windows.Forms.ColumnHeader
    40.     Friend WithEvents CustView As System.Windows.Forms.ListView
    41.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    42.         Me.TextBox1 = New System.Windows.Forms.TextBox
    43.         Me.Label1 = New System.Windows.Forms.Label
    44.         Me.CustView = New System.Windows.Forms.ListView
    45.         Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
    46.         Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
    47.         Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
    48.         Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
    49.         Me.ColumnHeader5 = New System.Windows.Forms.ColumnHeader
    50.         Me.SuspendLayout()
    51.         '
    52.         'TextBox1
    53.         '
    54.         Me.TextBox1.Location = New System.Drawing.Point(88, 16)
    55.         Me.TextBox1.Name = "TextBox1"
    56.         Me.TextBox1.Size = New System.Drawing.Size(248, 20)
    57.         Me.TextBox1.TabIndex = 0
    58.         Me.TextBox1.Text = ""
    59.         '
    60.         'Label1
    61.         '
    62.         Me.Label1.Location = New System.Drawing.Point(12, 16)
    63.         Me.Label1.Name = "Label1"
    64.         Me.Label1.Size = New System.Drawing.Size(76, 23)
    65.         Me.Label1.TabIndex = 2
    66.         Me.Label1.Text = "Search For:"
    67.         Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
    68.         '
    69.         'CustView
    70.         '
    71.         Me.CustView.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4, Me.ColumnHeader5})
    72.         Me.CustView.Location = New System.Drawing.Point(8, 48)
    73.         Me.CustView.Name = "CustView"
    74.         Me.CustView.Size = New System.Drawing.Size(576, 312)
    75.         Me.CustView.TabIndex = 0
    76.         Me.CustView.View = System.Windows.Forms.View.Details
    77.         '
    78.         'ColumnHeader1
    79.         '
    80.         Me.ColumnHeader1.Text = "Account Number"
    81.         Me.ColumnHeader1.Width = 100
    82.         '
    83.         'ColumnHeader2
    84.         '
    85.         Me.ColumnHeader2.Text = "First Name"
    86.         Me.ColumnHeader2.Width = 100
    87.         '
    88.         'ColumnHeader3
    89.         '
    90.         Me.ColumnHeader3.Text = "Initial"
    91.         Me.ColumnHeader3.Width = 100
    92.         '
    93.         'ColumnHeader4
    94.         '
    95.         Me.ColumnHeader4.Text = "Last Name"
    96.         Me.ColumnHeader4.Width = 100
    97.         '
    98.         'ColumnHeader5
    99.         '
    100.         Me.ColumnHeader5.Text = "City"
    101.         Me.ColumnHeader5.Width = 100
    102.         '
    103.         'frmCustomerList
    104.         '
    105.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    106.         Me.AutoScroll = True
    107.         Me.ClientSize = New System.Drawing.Size(594, 368)
    108.         Me.Controls.Add(Me.CustView)
    109.         Me.Controls.Add(Me.Label1)
    110.         Me.Controls.Add(Me.TextBox1)
    111.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    112.         Me.MaximizeBox = False
    113.         Me.MinimizeBox = False
    114.         Me.MinimumSize = New System.Drawing.Size(600, 400)
    115.         Me.Name = "frmCustomerList"
    116.         Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide
    117.         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    118.         Me.Text = "Customer Lookup"
    119.         Me.ResumeLayout(False)
    120.  
    121.     End Sub
    122.  
    123. #End Region
    124.     Private Sub frmCustomerList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    125.         Try
    126.             Dim cn As New SqlConnection("Server=LAPTOP\COMPLETEFMS;Database=CompleteFMS;User ID=sa;Password=test;Trusted_Connection=False")
    127.             cn.Open()
    128.             Dim cmdText As String = "SELECT CustAccountNumber, CustFirstName, CustInitial, CustLastName, CustCity FROM Customers"
    129.             Dim cm As New SqlCommand(cmdText, cn)
    130.  
    131.             Dim dr As SqlDataReader = cm.ExecuteReader
    132.             Dim i As Integer = 0
    133.             While dr.Read
    134.                 CustView.Items.Add(dr(0))
    135.                 CustView.Items(i).SubItems.Add(dr(1))
    136.                 CustView.Items(i).SubItems.Add(dr(2))
    137.                 CustView.Items(i).SubItems.Add(dr(3))
    138.                 CustView.Items(i).SubItems.Add(dr(4))
    139.                 i += 1
    140.             End While
    141.         Catch ex As Exception
    142.             MessageBox.Show(ex.Message)
    143.         End Try
    144.     End Sub
    145. End Class

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