Click here to Skip to main content
15,868,349 members
Please Sign up or sign in to vote.
2.41/5 (5 votes)
what is the problem at button5 ? When you click does nothing pls help .



C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;



namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        OpenFileDialog ofd = new OpenFileDialog();
        FolderBrowserDialog fbd = new FolderBrowserDialog();
      

        private void button1_Click(object sender, EventArgs e)
        {
            ofd.Filter = "PNG files |*.png|JPG files|*.jpg|JPGE files|*.jpge|DOC files|*.doc|DOCX files|*.docx|MP3 files|*.mp3|PDF files |*.pdf";


            ofd.Multiselect = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string[] fileNameAndPath = ofd.FileNames;
                string[] filename = ofd.SafeFileNames;
                for (int i = 0; i < ofd.SafeFileNames.Count(); i++)
                {
                    listView1.Items.Add(filename[i]);
                }
            }
        }

     

        private void button2_Click(object sender, EventArgs e)
        {
           
            if (fbd.ShowDialog() == DialogResult.OK)
            {
         
                string folderpath = fbd.SelectedPath;
             
                string supportedExtensions = "*.jpg,*.png,*.jpge,*.doc,*.docx,*.mp3,*.pdf";
                foreach (string f in Directory.GetFiles(folderpath, "*.*", SearchOption.AllDirectories).Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower())))
                {
                    ListViewItem lvi = new ListViewItem();
                    listView1.Items.Add(Path.GetFileName((f)));
                    lvi.SubItems.Add(Path.GetFullPath((f)));
                    listView1.Items.Add(lvi);
                       
         
                    
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        { 
            for (int i = 0; i < listView1.Items.Count; i++)
            
                if (listView1.Items[i].Selected)
                {
                    listView1.Items[i].Remove();
                    i--;
                }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            listView1.Items.Remove(listView1.SelectedItems[0]);
           

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
           
        }

        private void infoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("lalala");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //face legatura cu al doile form
            Form2 ff=new Form2();
            ff.MdiParent=this;
            //sortare
         for (int j = 0;j< listView1.Items.Count - 1; j++)
            {
                string sc = Convert.ToString(listView1.Items[j].Text);
                for (int j1 = 0; j1 < listView1.Items.Count; j1++)
                    if (String.CompareOrdinal(sc, Convert.ToString(listView1.Items[j1].Text)) < 0)
                    {
                        ListViewItem l = new ListViewItem(listView1.Items[j].Text,0);
                        l.SubItems.Add(Convert.ToString(listView1.Items[j].SubItems[1].Text));
                        listView1.Items.RemoveAt(j);
                        listView1.Items.Insert(j, listView1.Items[j1]);
                        listView1.Items.Insert(j1, l);
                        
                    }
        }

       //foreach (ListViewItem item in listView1.Items)
             // verifica daca au acelasi nume,tip,marime 
               for (int j = 0;j< listView1.Items.Count - 1; j++)
            {
             string str = Convert.ToString(listView1.Items[j].SubItems[1].Text);
             string s = Path.GetFileName(str);
                  for (int j1 = 0; j1 < listView1.Items.Count; j1++)
                  {
                      string str2=Convert.ToString(listView1.Items[j1].SubItems[1].Text);
                 if (s.Equals(Path.GetFileName(str2)) )
                 {
                     FileInfo f = new FileInfo(str);
	                  long s1 = f.Length;
	                FileInfo f2 = new FileInfo(str2);
	                long s2 = f2.Length;

                    if (s1.Equals(s2))
                    {//trimite catre form2
                        ff.valoaretransmisa = listView1.Items[j];
                    }

                     }
                  }
                 }




            ff.ShowDialog();
            
           


             }

      
       


      
      

        
    }
}



C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication2
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

      private ListViewItem lvi;
         public ListViewItem  valoaretransmisa
        {
            get { return lvi; }
            set { lvi=value;
                listView1.Items.Add(lvi); }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Vrei sa stergi?","titlu", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            == DialogResult.Yes)
            {

                for (int i = 0; i < listView1.Items.Count; i++)
                    File.Delete(Convert.ToString(listView1.Items[i].SubItems[1].Text));
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        }     
    
}
Posted
Comments
Sinisa Hajnal 25-Nov-14 9:43am    
Does it enter the function? Put a breakpoint in it and step through. Do you get any errors? Put Try Catch around the code and see if one of the loops fails.

When you step through and get the error then come back if you cannot solve it.
Ainy Mughal 27-Nov-14 2:37am    
Check their mapping.
Swinkaran 14-Dec-14 16:58pm    
does it hit the function?

Hi,

let's have a look at an example Windows Forms application.

Form1.cs
C#
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}


If you have Form1.cs there will also be
Form1.Designer.cs
XML
namespace WindowsFormsApplication2
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(12, 12);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button button1;
    }
}


which is auto-generated and auto-updated when e.g. you drag a button
to the Windows Form and assign a double-click.
Please check if all button click events are wired up.
e.g. this.button5.Click += new System.EventHandler(this.button5_Click);

Best regards,
Stephan
 
Share this answer
 
The button and event might have got disconnected.
Check the button and its mapping code to the click event.
 
Share this answer
 
Both of the above suggestions are GOOD ones.

Stepping through in the Debug mode will allow you see what happens when you click the button. You could alwats set a "BreakPoint" at the button5_click(), then run in debug. It should stop when you click the button and show the code for you to use F11 to step through.

If it never gets here, or doesn't break, then check your button's "Click" property and make sure it's pointing to the button5_Click() method.
 
Share this answer
 
Just put a messagebox on that button-Click event to know that it is calling or not
MessageBox.Show();
 
Share this answer
 
The debugger allows you to step through code line by line
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900