Solved

Line up List Items

Posted on 2006-06-28
7
209 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 3

Author Comment

by:JasonWinn
Comment Utility
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
Comment Utility
I would suggest a DataGridView configured to look like a ListBox (grid lines turned off, etc.).

Bob
0
 
LVL 3

Author Comment

by:JasonWinn
Comment Utility
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
Comment Utility
So, you either didn't have time, or you figured it out yourself ;)

Bob
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now