المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : OpenFileDialog: Files of Type doesn't respond [modified]



C# Programming
06-07-2011, 03:11 AM
Hello all, I am now learning to program in C#. I initialised an object of OpenFileDialog and set the filter. When the dialog box opens for the first time, everything seems to be OK. Files of the type specified in the filter a shown. But when I change Files of Type to All files which I have set with *.*, the list of files shown is not automatically updated as is expected. I don't know what is wrong. The following is the code I have.

using System; using System.Drawing; using System.Windows.Forms; class MyForm : Form { public static void Main() { Application.Run(new MyForm()); } public MyForm() { Text = "My Form"; Menu = new MainMenu(); Menu.MenuItems.Add("&File"); Menu.MenuItems[0].MenuItems.Add("&Open...", new EventHandler(FileOpenOnClick); } void FileOpenOnClick(object obj, EventArgs ea) { OpenFileDialog fodlg = new OpenFileDialog(); fodlg.Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"; if (fodlg.ShowDialog() == DialogResult.OK) { // some code here } // some code here } }
I am using Visual Studio 2005 with .Net Framework 2.0. From the code above, I have only set the Filter property. When the file open dialog box opens first with Text documents, it works fine but when I change the Files of Type from the combobox to All Files, the dialog box is not updated to show all files. What could be wrong? What am I missing? Please help.

modified on Monday, June 6, 2011 10:01 AM