Indenting text items in a ASP.Net 2.0 ListBox

Posted on 2007-03-20
Last Modified: 2013-11-26

I have an application that builds an itinerary. I have the origin, destinations/stopovers and vias added to the same listbox. I have a checkbox that the user can check to indicate that this part of the itinerary is a 'via' i.e. the user wants to go via this city but this is not a stopover or destination where they will actually stop.

For example, a person goes from Chicago to Orlando stopping in Nashville but going via Louisville, KY.

So the listbox should be:

Chicago (origin)
Nashville (stopover)
-->Louisville (indented by tab or spaces to indicate it is a 'via')
Orlando (final destination)

How can this best be accomplished?

Thanks in advance.

Question by:chad_sriram
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
  • 3
  • 2

Author Comment

ID: 18770940
Any ideas, fellas?


Expert Comment

ID: 18805672
Not sure if this will work but try adding $nbsp; in front of the listbox item text, add it multiple times for multiple spaces.  I didn't test this out but it may work.  Also you can just create a custom control that either uses a table or span tags and then you can control the exact location of the text depending on what it is.

Expert Comment

ID: 18805674
sorry its not $nbsp; its      having a bad typing day.

Author Comment

ID: 18807566
I tried

strVia = "Nashville";
ListBoxViaList.Items.Add("   " + strVia );

The item displays as    Nashville in my listbox item.
It does not render the &nbsp right, must be something that ASP.Net listbox is picky about.

Accepted Solution

whylogin earned 500 total points
ID: 18808213
You can try something like this,  once again I haven't tried this.

strVia = (Char)32 + "Nashville";

Generally what I would do in this case is just create a custom control that displays a table.  Then you can control the spacing, padding, alignment and everything using css.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

705 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