?
Solved

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

Posted on 2006-11-19
2
Medium Priority
?
191 Views
Last Modified: 2010-04-16
If not, is Listview the only control suitable for this?  Thanks.
0
Comment
Question by:lapucca
[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 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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