I have the following code for adding information from and array to a listbox

    private void buttonAdd_Click(object sender, EventArgs e)
          //add tracks to my tracks Add Tracks list box and tracks list box

            myTracksString[nextAvailbleRow, 0] = textBoxArtist.Text;
            myTracksString[nextAvailbleRow, 1] = textBoxSongName.Text;
            myTracksString[nextAvailbleRow, 2] = ((numericUpDownHours.Value * 3600) + (numericUpDownMinutes.Value * 60) + numericUpDownSeconds.Value).ToString();

            textBoxSongName.Text = "";
            textBoxArtist.Text = "";
            numericUpDownHours.Value = 0;
            numericUpDownMinutes.Value = 0;
            numericUpDownSeconds.Value = 0;


            for (int indexInteger = 0; indexInteger <= 199; indexInteger++)
                listBoxAddTrack.Items.Add(myTracksString[indexInteger, 0] + "   " + myTracksString[indexInteger, 1] + "  " + myTracksString[indexInteger, 2]);


The issue I have is when I add the information it doesn't line up in columns i.e. row 1 has 3 columns but then in row 2 the columns line up differently if the number of letters in that column is more than the number of letters in column 1, row 1.

So what I am wanting to know is how can I write some code that allows each column to line up in the same place regardless of how many letters are in each word. Hope that makes sense !!

Edited by pyTony: fixed formatting

7 Years
Discussion Span
Last Post by abelLazm

Plz place CODE tags around your code to separate it from other text

Edited by happygeek: fixed formatting


Use two listboxes instead of using one and use them as 2 columns another way is to use datagridview instead of listbox..... Can you please tell about the type of your data any what functions are you going to apply on the list box


what I am after is that in one column the artist will line up, then in the next column the name of the song will line up and finally in the last column the time in seconds of the song will line up.

In terms of the data it is just going to be displayed, but it has to be in just one list box

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.