Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Line up List Items

Posted on 2006-06-28
7
Medium Priority
?
218 Views
Last Modified: 2008-02-01
Hello,
I have a listbox and I am trying to add multiple lines of data, but I would like the data to be split up into 3 columns and have it all lined up.
I tried using Vtab (with multi columns on and off, get weird reslts either way) and my data looks like this
A
A
A
A
      B
      B
      B
      B
               C
               C
               C
               C

I am trying to get it to look like
A B C
A B C
A B C
A B C


This is what I have, but not sure where i went wrong and what properties should be set on the listbox (multi column or not)


        NameList = xDoc.SelectNodes("//FirstName[. = '" & firstNameLookUp.Text & "']/parent::node()/FirstName")
        LastList = xDoc.SelectNodes("//FirstName[. = '" & firstNameLookUp.Text & "']/parent::node()/LastName")
        SSNList = xDoc.SelectNodes("//FirstName[. = '" & firstNameLookUp.Text & "']/parent::node()/SSN")

        For Each node In NameList
            ListBox1.Items.Add(node.InnerText)

        Next
        For Each node In LastList
            ListBox1.Items.Add(vbTab & node.InnerText)

        Next
        For Each node In SSNList
            ListBox1.Items.Add(vbTab & vbTab & node.InnerText)

        Next


0
Comment
Question by:JasonWinn
7 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 17005794
Looking at your XPath I think you may be overcomplicating things a little.

   NameList = sDoc.SelectNodes("//*[FirstName='" & firstNameLookup.Text & "']")

Will grab the parent node of any FirstName that matches your lookup value. This means that FirstName, LastName as SSN will be grouped together making it a lot easier, and quicker, to format the how you want. I'm assuming that your XML looks something like:

     <parentNode>
        <FirstName>Bob</FirstName>
        <LastName>Smith</LastName>
        <SSN>12345678</SSN>
     </parentNode>

If thats the case then you can then use the following to add each to the list and format them:

        For Each node In NameList
            Dim s As StringBuilder = New StringBuilder()
            s.Append(node("FirstName").InnerText & vbTab)
            s.Append(node("LastName").InnerText & vbTab)
            s.Append(node("SSN").InnerText)
            ListBox1.Items.Add(s.ToString())
        Next
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17008642
A ListBox is not the easiest control to do that.

What .NET version do you have?  2002, 2003, or 2005

Bob
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 17008714
here is the code how to set tabs in listbox

Imports System.Runtime.InteropServices

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.ListBox2 = New System.Windows.Forms.ListBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.ListBox1.Location = New System.Drawing.Point(8, 24)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(248, 95)
        Me.ListBox1.TabIndex = 0
        '
        'ListBox2
        '
        Me.ListBox2.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.ListBox2.Location = New System.Drawing.Point(8, 152)
        Me.ListBox2.Name = "ListBox2"
        Me.ListBox2.Size = New System.Drawing.Size(248, 95)
        Me.ListBox2.TabIndex = 1
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(128, 16)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Without Tabs"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 136)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(128, 16)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "With Tabs"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(264, 253)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.ListBox2)
        Me.Controls.Add(Me.ListBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    Private Const LB_SETTABSTOPS As Integer = &H192

'LB1 w/o tabs LB2 - with tabs


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBox1.Items.Add("Amphibian" & vbTab & "Ash" & vbTab & "Auto")
        ListBox1.Items.Add("Mammal" & vbTab & "Beech" & vbTab & "Bus")
        ListBox1.Items.Add("Reptile" & vbTab & "Chokecherry" & vbTab & "Cart")

        ListBox2.Items.Add("Amphibian" & vbTab & "Ash" & vbTab & "Auto")
        ListBox2.Items.Add("Mammal" & vbTab & "Beech" & vbTab & "Bus")
        ListBox2.Items.Add("Reptile" & vbTab & "Chokecherry" & vbTab & "Cart")

        Dim tabs() As Integer = {60, 120}
        SetListBoxTabs(ListBox2, tabs)
    End Sub

    Private Sub SetListBoxTabs(ByVal list_box As ListBox, ByVal tab_stops() As Integer)
        Dim pinned_array As GCHandle = GCHandle.Alloc(tab_stops, GCHandleType.Pinned)
        SendMessage( _
            list_box.Handle, _
            LB_SETTABSTOPS, _
            New IntPtr(tab_stops.Length), _
            pinned_array.AddrOfPinnedObject)
        pinned_array.Free()

        list_box.Refresh()
    End Sub
End Class
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:JasonWinn
ID: 17009475
Bob,
I have the latest .NET version. What do you recommend be the easiest way then?

Jason
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17009508
I would suggest a DataGridView configured to look like a ListBox (grid lines turned off, etc.).

Bob
0
 
LVL 3

Author Comment

by:JasonWinn
ID: 17009521
Bob,
That does sound better. Because what is going to be happening is I am pulling information from the XML sheet, and the user will then be selecting from the results and sending the results back to a textbox.

What is the best way to pull the informatio nfrom that XML sheet and put it into a datagridview? Thanks! Jason
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17010285
So, you either didn't have time, or you figured it out yourself ;)

Bob
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question