Solved

vb.net, listbox header

Posted on 2014-11-13
2
1,145 Views
Last Modified: 2014-11-14
On a vb.net winform below, A is what I have.
Question: Is it possible to make changes to the header area, as shown on B above?
headerLike:
1. Add a continuous line under header captions.
2. Make header text bold, change its size, etc.

The code populating this listbox is:
      lstCustomers.Items.Add("Cust ID" & ControlChars.Tab & "F. Name" & ControlChars.Tab & _
                               "L. Name" & ControlChars.Tab & "City" & ControlChars.Tab & "State")

        lstCustomers.Items.Add("-------" & ControlChars.Tab & "-------" & ControlChars.Tab & _
                               "-------" & ControlChars.Tab & "-------" & ControlChars.Tab & "-------")

        ' ADD CUSTOMERS TO lstCustomers
        For Each customer In customers
            lstCustomers.Items.Add(customer.CustomerID & ControlChars.Tab & _
                                                      customer.FirstName & ControlChars.Tab & _
                                                      customer.LastName & ControlChars.Tab & _
                                                      customer.State & ControlChars.Tab & _
                                                      customer.City)
        Next

Open in new window

0
Comment
Question by:Mike Eghtebas
2 Comments
 
LVL 11

Assisted Solution

by:Deepak Lakkad
Deepak Lakkad earned 150 total points
ID: 40441982
Hi,

At present, you are using ListBox control to show list of records.

You can use ListView Control to get desired result.

- Deepak Lakkad
0
 
LVL 11

Accepted Solution

by:
LordWabbit earned 350 total points
ID: 40442372
As Deepak said, you can get that using a listview instead of a listbox.  You set the columns in the properties (and their sizes) and change the View property of the listview to Details.  
Then when adding the customers you create a list view item whose value will be in the first column, and then for each subsequent column you add a sub item.  Like this...

        Dim customers As New List(Of Customer)
        customers = db.Customers.ToList()
        For Each customer As Customer In customers
            Dim cust As New ListViewItem(customer.CustomerID)
            cust.SubItems.Add(customer.FirstName)
            cust.SubItems.Add(customer.LastName)
            cust.SubItems.Add(customer.State)
            lstCustomers.Items.Add(cust)
        Next

Open in new window


Which will give you something that is closer to what you want.
EE-Untitled.png
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

22 Experts available now in Live!

Get 1:1 Help Now