Solved

vb.net, listbox header

Posted on 2014-11-13
2
1,375 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
[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
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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