Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

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

If not, is Listview the only control suitable for this?  Thanks.
Avatar of DrAske
DrAske
Flag of Jordan image

>>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;
ASKER CERTIFIED SOLUTION
Avatar of WinterMuteUK
WinterMuteUK
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial