[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Showing the name of the first file in a folder as the first value in a combo box

Posted on 2005-05-09
2
Medium Priority
?
211 Views
Last Modified: 2010-04-16
I have a form load event which grabs all the files in a folder and list the names in a combo box. Anytime my form loads, it comes up with a blank default value in the combo box and i will have to click on the combo box to select a file. I want to be able to have the first file in my folder to be the default file when the form loads. Any help please?


private void Form1_Load(object sender, System.EventArgs e)
            {
                  try
                  {
                        DirectoryInfo myfolder = new DirectoryInfo(System.Windows.Forms.Application.StartupPath);
                        foreach(FileInfo nextFile in myfolder.GetFiles("*.txt"))
                        {
                              string[]fileName = nextFile.Name.Split('.');
                              cmbTemplates.Items.Add(fileName[0]);
                        }
                        
                  }
                  catch(Exception ex)
                  {
                        MessageBox.Show(ex.Message);
                  }
            }
0
Comment
Question by:Sirdots
  • 2
2 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 13960134
private void Form1_Load(object sender, System.EventArgs e)
          {
               try
               {
                    DirectoryInfo myfolder = new DirectoryInfo(System.Windows.Forms.Application.StartupPath);
                    foreach(FileInfo nextFile in myfolder.GetFiles("*.txt"))
                    {
                         string[]fileName = nextFile.Name.Split('.');
                         cmbTemplates.Items.Add(fileName[0]);
                    }
                    cmbTemplates.SelectedItem = 0;
                   
               }
               catch(Exception ex)
               {
                    MessageBox.Show(ex.Message);
               }
          }
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 13960144
Sorry, correction:

cmbTemplates.SelectedIndex = 0;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 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