Solved

Line up List Items

Posted on 2006-06-28
7
211 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
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to retrieve a mysql date column that has 0000-00-00 in vb.net 8 36
SQL LINE CONTINUATION ISSUE 12 33
Modal Popup Extender control 1 22
Expression Evaluater 3 27
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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