Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
192 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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