Rudy Escamilla

Rudy Escamilla

  • NA
  • 4
  • 1.4k

Need some Guidance comparing to listboxes on a windows forms

Jan 29 2016 11:59 AM

 I have created a GUI (Windows Form) that has FileBrowserdialogs in which you can choose the folder and display the contents on each listbox respectively. However, I want to compare both list boxes and display the differences in the strings on the third list box by pressing a button. For example:

 List Box 1
(XXXX_YYYY_ZZZZ_4R_5KL_CM12345_L_88%_0.01_v1) 
 
List Box 2 
(XXXX_YYYY_ZZZZ_4R_5KL_CM12346_L_90%_0.01_v1)
 
Usually, the string will have  changes in the highlighted area but the unhighlighted area will have the same text for each item. I am new to C# so any
help would be much appreciated. Below is my code:
 
 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.IO;

 

namespace WindowsFormsApplication3

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            FolderBrowserDialog FBD = new FolderBrowserDialog();

 

            if (FBD.ShowDialog() == DialogResult.OK)

            {

 

                listBox1.Items.Clear();

                string[] files = Directory.GetFiles(FBD.SelectedPath);

                string[] dirs = Directory.GetDirectories(FBD.SelectedPath);

 

                foreach (string file in files)

                {

                    listBox1.Items.Add(file);

                }

 

                foreach (string dir in dirs)

                {

                    listBox1.Items.Add(dir);

                }

 

            }

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            FolderBrowserDialog FBD = new FolderBrowserDialog();

            if (FBD.ShowDialog() == DialogResult.OK)

            {

                listBox2.Items.Clear();

                string[] files = Directory.GetFiles(FBD.SelectedPath);

                string[] dirs = Directory.GetDirectories(FBD.SelectedPath);

 

                foreach (string file in files)

                {

                    listBox2.Items.Add(file);

                }

 

                foreach (string dir in dirs)

                {

                    listBox2.Items.Add(dir);

                }

            }

            {

            }

        }

 

        private void button3_Click(object sender, EventArgs e)

        {

 

        }

    }

}


Answers (3)