Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Line up List Items

Posted on 2006-06-28
7
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

705 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