Solved

Can a Listbox control be configure to several Columns and each column with its own heading?

Posted on 2006-11-19
2
185 Views
Last Modified: 2010-04-16
If not, is Listview the only control suitable for this?  Thanks.
0
Comment
Question by:lapucca
2 Comments
 
LVL 9

Expert Comment

by:DrAske
Comment Utility
>>each column with its own heading?
I don't think so.

but you can add serveral columns from a table to list box (but it is a tricky way) ..
assume you have a table .Say, "TableName" with the following columns( ID, UserName, UserNo)
in your code establish a connection with the database, then load the data by using dataprovider to your dataset.
Now, To be Allowed to show several columns of that table, you need to add another column to "TableName" in the dataset, Say, "col" and this column is of type string and is a concatenation of the columns you want to show in the list box.

ID           UserName      UserNo      col
====================================
"1"         "lapucca"         "12345"      "1 lapucca 12345"
"2"         "DrAske"          "00000"      "2 DrAske  00000"

To add a new column to "TableName" in the dataSet add this line to your code :

yourDataSet.Tables["TableName"].Columns.Add("col",typeof(string),"ID +'\t'+UserName+'\t'+UserNo");
Now, the column "col" is added to your table.

To fill the list box with data do this :

yourListBox.DataSource = yourDataSet.Tables["TableName"];
yourListBox.DisplayMember = "col";

And thats it ;o)

hope that helps,
regards,Ahmad;
0
 
LVL 9

Accepted Solution

by:
WinterMuteUK earned 500 total points
Comment Utility
Hullo lapucca,

The easiest thing for you to do (I would have thought) would be to use a ListView instead of a ListBox, that way you could have your columns and headings as you want them.

Wint
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

7 Experts available now in Live!

Get 1:1 Help Now