C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,175 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,576 people online right now. Registration is fast and FREE... Join Now!




Handling events

 

Handling events

Poornima Mani

3 Feb, 2009 - 07:17 AM
Post #1

D.I.C Head
**

Joined: 24 Jan, 2009
Posts: 178

I have used this code for handling the SelectedIndexChanged event for listing files from all drives displayed in the listbox:

CODE


protected delegate void EventHandler(object sender, EventArgs args);

    protected void InitializeComponent(object sender, EventArgs e)
    {
        this.ListBox1.SelectedIndexChanged += new EventHandler(this.ListBox1_SelectedIndexChanged);

    }

    protected void ListBox1_SelectedIndexChanged(object sender,EventArgs args)
    {
        protected void onList(object sender,EventArgs args);
        protected void onListSub(object sender,EventArgs args);
    }

    protected void onList(object sender, EventArgs e)
    {
        string[] drives = Environment.GetLogicalDrives();
        // Loop into the string array
        foreach (string strDrive in drives)
        {
            // Add items (drives) to the list
            ListBox1.Items.Add(strDrive.ToString());
            //Panel1.ID    oad(strDrive.ToString());
        }
    }

      protected void onListSub(object sender, EventArgs e)
    {
       try
        {
            String curdir;
            //String path = ListBox3.SelectedValue;
            curdir = ListBox1.SelectedItem.Text;
            string[] Dirs = Directory.GetDirectories(curdir);
            foreach (string s in Dirs)
            {
                ListBox3.Items.Add(s.ToString());
                foreach (string s1 in Directory.GetDirectories(s))
                {
                    ListBox3.Items.Add(s1.ToString());
                    foreach (string s2 in Directory.GetDirectories(s1))
                    {
                        ListBox3.Items.Add(s2.ToString());
                    }
                }
            }            
            DirectoryInfo di = new DirectoryInfo("C:/WINDOWS/system32");
            FileInfo[] rgFiles = di.GetFiles("*.exe");
            foreach (FileInfo fi in rgFiles)
            {
               ListBox4.Items.Add(fi.ToString());
            }

         }
        catch (IOException ex)
        {
            Response.Write(ex);
        }
            
    }


I am getting errors:

Error    2    Expected class, delegate, enum, interface, or struct    

Error    5    Type or namespace definition, or end-of-file expected    




User is offlineProfile CardPM
+Quote Post


Posts in this topic
Poornima Mani   Handling events   3 Feb, 2009 - 07:17 AM
Jayman   Is there a question related to this code or are yo...   3 Feb, 2009 - 10:22 AM
b.ihde   There are 2 errors in the end of the code :)   3 Feb, 2009 - 10:25 AM

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:06PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month