Click here to Skip to main content
15,902,735 members
Home / Discussions / C#
   

C#

 
AnswerRe: Drive Control Pin
amiralimadadi1-Feb-09 17:52
amiralimadadi1-Feb-09 17:52 
AnswerRe: Drive Control Pin
Dragonfly_Lee1-Feb-09 19:02
Dragonfly_Lee1-Feb-09 19:02 
GeneralRe: Drive Control Pin
amiralimadadi3-Feb-09 18:05
amiralimadadi3-Feb-09 18:05 
GeneralRe: Drive Control Pin
amiralimadadi17-Feb-09 1:46
amiralimadadi17-Feb-09 1:46 
Questionhow to paste graphic object on screen from arraylist...in c#.net Pin
priyareguri1-Feb-09 0:57
priyareguri1-Feb-09 0:57 
AnswerRe: how to paste graphic object on screen from arraylist...in c#.net Pin
Natza Mitzi1-Feb-09 3:37
Natza Mitzi1-Feb-09 3:37 
GeneralRe: how to paste graphic object on screen from arraylist...in c#.net Pin
priyareguri1-Feb-09 13:24
priyareguri1-Feb-09 13:24 
QuestionProblem with Listbox and removing items... [modified] Pin
Matjaz-xyz31-Jan-09 23:41
Matjaz-xyz31-Jan-09 23:41 
Hi.

I'm making an application and have a lot of problems.

First of all, i had trouble figuring out - how to get all the items to lower case.

Ok, i fixed that... but the program doesnt work the way it should.

So, the program should work this way:

You start the app. Then u click the button to get all the files from directory and all subdirectories. This goes ok. Ok, but then, i want to remove all doubles in the list.

If theres a file "BeBack.JPG" the app. should check if there's also "BeBack.PDF" or if theres "BlackWhite.PDF" and "BlackWhite_1.PDF" it should remove both entries from the listbox.
My code doesnt do that Frown | :( i dont know why Frown | :( It also deosnt remove all .gif files Frown | :(

Where did i go wrong? Please help?

Here's the code:


 private void button1_Click(object sender, EventArgs e)
        {
// for getting the items ToLower case
            string[] fajli = Directory.GetFiles(Application.StartupPath,"*.*",SearchOption.AllDirectories);
            string[] VsiFajli = Array.ConvertAll<string,>(fajli, delegate(string s) { return s.ToLower(); });

            listBox1.Items.AddRange(VsiFajli);

            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                // checks if the file is .pdf
                if (listBox1.Items[i].ToString() == listBox1.Items[i].ToString().Remove(listBox1.Items[i].ToString().Length - 4, 4) + ".pdf")
                {
                    if (File.Exists(listBox1.Items[i].ToString().Remove(listBox1.Items[i].ToString().Length - 4,4) + "_1.pdf"))
                    {
                        string temp = listBox1.Items[i].ToString();
                        
                        listBox1.Items.Remove(temp);
                        listBox1.Items.Remove(temp.Remove(temp.Length - 4,4) + "_1.pdf");


                        //listBox1.Items.RemoveAt(i);
                    }
                }
                else // if its not pdf ...
                {
                    if (File.Exists(listBox1.Items[i].ToString().Remove(listBox1.Items[i].ToString().Length - 4,4) + ".pdf"))
                    {
                        string temp = listBox1.Items[i].ToString();
                        listBox1.Items.Remove(temp);
                        listBox1.Items.Remove(temp.Remove(temp.Length - 4,4) + ".pdf");
                        listBox1.Items.Remove(temp.Remove(temp.Length - 4, 4) + "_1.pdf");


                        //listBox1.Items.RemoveAt(i);
                    }
                }
            }
            MessageBox.Show("Done!");
        }

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            if(listBox1.SelectedItem!=null)
            System.Diagnostics.Process.Start(listBox1.SelectedItem.ToString());
        }

        private void button2_Click(object sender, EventArgs e)
        {
// for removing all .gif items
            if(listBox1.Items.Count != 0)
            for (int j = 0; j < listBox1.Items.Count; j++)
            {
                if(listBox1.Items[j].ToString() == (listBox1.Items[j].ToString().Remove(listBox1.Items[j].ToString().Length-4,4) + ".gif"))
                    listBox1.Items.RemoveAt(j);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
// copying the selected item to clipboard.
            if (listBox1.SelectedItem != null)
                Clipboard.SetText(listBox1.SelectedItem.ToString()) ;
        }



Thanks in advance.

Regards,
Matjaž

modified on Sunday, February 1, 2009 7:30 AM

AnswerRe: Problem with Listbox and removing items... Pin
User 66581-Feb-09 0:50
User 66581-Feb-09 0:50 
GeneralRe: Problem with Listbox and removing items... Pin
Matjaz-xyz1-Feb-09 1:33
Matjaz-xyz1-Feb-09 1:33 
AnswerRe: Problem with Listbox and removing items... Pin
Dragonfly_Lee1-Feb-09 19:09
Dragonfly_Lee1-Feb-09 19:09 
Questionc# code to execute a particular method every 5 mints? Pin
merryjoy00031-Jan-09 23:24
merryjoy00031-Jan-09 23:24 
AnswerRe: c# code to execute a particular method every 5 mints? Pin
Giorgi Dalakishvili31-Jan-09 23:38
mentorGiorgi Dalakishvili31-Jan-09 23:38 
AnswerRe: c# code to execute a particular method every 5 mints? Pin
merryjoy00031-Jan-09 23:43
merryjoy00031-Jan-09 23:43 
GeneralRe: c# code to execute a particular method every 5 mints? Pin
ajorge20081-Feb-09 0:32
ajorge20081-Feb-09 0:32 
AnswerRe: c# code to execute a particular method every 5 mints? Pin
Giorgi Dalakishvili1-Feb-09 3:21
mentorGiorgi Dalakishvili1-Feb-09 3:21 
AnswerRe: c# code to execute a particular method every 5 mints? Pin
PIEBALDconsult2-Feb-09 4:41
mvePIEBALDconsult2-Feb-09 4:41 
QuestionHow to make Gsm Sequential calls without blocking my application Pin
ajorge200831-Jan-09 23:02
ajorge200831-Jan-09 23:02 
QuestionRepost from ASP.NET forum - VBRUN : 80040154 Pin
coolestCoder31-Jan-09 21:39
coolestCoder31-Jan-09 21:39 
QuestionMp3 Spliting Pin
Learn Searcher31-Jan-09 21:18
Learn Searcher31-Jan-09 21:18 
AnswerRe: Mp3 Spliting Pin
Christian Graus31-Jan-09 22:05
protectorChristian Graus31-Jan-09 22:05 
AnswerRe: Mp3 Spliting Pin
Dragonfly_Lee1-Feb-09 20:17
Dragonfly_Lee1-Feb-09 20:17 
Questionwhen a method is called i want to get first index value from an arraylist and when the same methid is called nxt time i want to get the second index value from the same arraylist...how? Pin
merryjoy00031-Jan-09 20:30
merryjoy00031-Jan-09 20:30 
AnswerRe: when a method is called i want to get first index value from an arraylist and when the same methid is called nxt time i want to get the second index value from the same arraylist...how? Pin
Kashif Sabir31-Jan-09 21:13
Kashif Sabir31-Jan-09 21:13 
AnswerRe: when a method is called i want to get first index value from an arraylist and when the same methid is called nxt time i want to get the second index value from the same arraylist...how? Pin
Dragonfly_Lee31-Jan-09 21:18
Dragonfly_Lee31-Jan-09 21:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.