Link to home
Start Free TrialLog in
Avatar of muffintwinkly
muffintwinkly

asked on

displaying file order in a listbox

Hi,

I am using a button and a listbox in my winform.
When I click the button, a user can select multiple files at the same time.
However, always the last selected file goes to the top of the list in the listbox.
how can I list the files in the listbox in order to be selected?  For example, if I select the 3 doc files with following order:1.doc, 2.doc and 3.doc, and add all of them at the same time, the list of file should be displayed as 1.doc, 2.doc, and 3.doc from top to bottom.

The following codes are for the button.

        private void button1_Click_1(object sender, EventArgs e)
        {
            dlg.Multiselect = true;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                foreach (string fileName in dlg.FileNames)
                {
                    textBox1.Text = fileName;
                    listBox1.Items.Add(Path.GetFileName(textBox1.Text));
                }
            }
        }
ASKER CERTIFIED SOLUTION
Avatar of jlj1527
jlj1527
Flag of Viet Nam 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
Avatar of muffintwinkly
muffintwinkly

ASKER

thanks! it works great.