Member 14077939 Ответов: 1

Как создать inovice в listbox на C#?


I want to create invoice in listbox but i can't arrange contents in sequence. If increase length of content, other contents move from their location. Please help me how can i create receipt in listbox.<pre>

What I have tried:

<pre> String dt = "{0, -30}{1,-10}{2,-10}";
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String Id, Naame,abd;

            Id = textBox1.Text;
            Naame = textBox2.Text;
            abd = textBox3.Text;

            listBox1.Items.Add(String.Format(dt, Id+"\n", Naame,abd));

        }

1 Ответов

Рейтинг:
1

RickZeeland

Попробуйте обойтись без символа новой строки "\n", он не нужен.

string dt = "{0, -10}{1, -20}{2, -10}";
listBox1.Font = new System.Drawing.Font("Courier New", 10);
listBox1.Items.Add(string.Format(dt, "4", "Jack", "4000"));
listBox1.Items.Add(string.Format(dt, "2", "Joe", "2000.20"));
listBox1.Items.Add(string.Format(dt, "3", "Jim", "3000"));
listBox1.Items.Add(string.Format(dt, "1", "John", "10.50"));
listBox1.Sorted = true;


Maciej Los

Ух ты!

RickZeeland

Спасибо, но я думаю, что есть место для улучшения, если явно установить культуру таким образом, чтобы использовался правильный десятичный разделитель и символ валюты ...

Maciej Los

Это само собой разумеется!