Solved

Line up List Items

Posted on 2006-06-28
7
215 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 500 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help converting bitmap to image in VB.Net 8 68
ModalPopup  question 22 56
how to remove error in database 6 55
How do i create a simple array in a public class? 6 37
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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