Solved

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

Posted on 2006-11-19
2
187 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
ID: 17977562
>>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
ID: 17977741
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with C#, MVC, razor. 6 34
Why does my excel data start at B1 instead of A1. 9 84
Reference issues in Visual Studio 3 30
C# bracket error 3 31
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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 …

809 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