Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,

I got some values from a text file to the listbox. And then I select a value in the listbox and send it to textbox. When I search this value into the listbox then it's been found. There is no any problem until here.. The problem is when I enter the value into the textbox manually then cannot be found into the listbox.

First, I select it by mouse and then it's been found.
However, when I type it into the textbox manually then it's been not found.

How can I solve this problem?

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.Collections;
using System.IO;

namespace WindowsFormsApplication16
{
    public partial class Form1 : Form
    {
        DataClasses1DataContext data;
        public Form1()
        {
            InitializeComponent();
            data = new DataClasses1DataContext();
        }
      
            ArrayList manular = new ArrayList();
       
        private void button1_Click(object sender, EventArgs e)
        {
            
            foreach (var st in data.DEPO_REFARANs.ToList())
            {
                manular.Add(st.BD_NO);
              
                
               
            }
           FileStream _oku=new FileStream(@"C:\Excel\P0186733.txt",FileMode.Open,FileAccess.Read);
              
            StreamReader oku = new StreamReader(_oku);
            FileStream _oku1 = new FileStream(@"C:\Excel\Veri.txt", FileMode.Open, FileAccess.Read);
            StreamReader oku1=new StreamReader(_oku1);

            string[] veriler = oku1.ReadToEnd().ToString().Split(',');
            
            for (int i = 0; i < veriler.Length; i++)
            {
                listBox2.Items.Add(veriler[i].ToString());
            }
            string[] _veri = oku.ReadToEnd().ToString().Split(' ');
            ArrayList veri = new ArrayList();
            for (int i = 0; i < _veri.Length; i++)
            {
                string deger = _veri[i].ToString();
                if (deger!="")
                {
                    veri.Add(deger);
                    listBox1.Items.Add(deger);
                }
            }
            for (int i = 0; i < veri.Count; i++)
            {
                string deger = veri[i].ToString();
                for (int k = 0; k < manular.Count; k++)
                {
                    string manu = manular[k].ToString();
                    
                    if (string.Compare(deger,manu)==0)
                    {
                        listBox1.Items.Add(_veri.ToString().Trim());
                    }
                }
            }
            oku.Close();
            oku1.Close();
            _oku.Close();
            _oku1.Close();

        }

        private void button2_Click(object sender, EventArgs e)
        {

            
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox1.Text = listBox1.SelectedItem.ToString();
            MessageBox.Show(listBox1.SelectedItem.ToString());
        }
    }
}


Regards

Haluk
Posted
Updated 11-Oct-12 1:43am
v2
Comments
OriginalGriff 11-Oct-12 7:41am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Sushil Mate 11-Oct-12 7:55am    
This must be your most copy & pasted lines ;)
OriginalGriff 11-Oct-12 8:06am    
Surprisingly, no - this is fourth! :laugh:
In third place is "We don't do homework" - the other two are message edit descriptions.

(I have a DB app to save typing, and it ranks them by use count)
Sushil Mate 11-Oct-12 8:30am    
Actually i like to see the comments/answers by you or SA... it's quite informative sometimes & amuses me ;)

:thumbsup: for your DB app
Tim Corey 11-Oct-12 8:32am    
I know I'm with my type of people when they have a database that stores and tracks their common responses for easier use and for reporting.

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