a = textBox3.Text;
       
            if (listBox1.Items.Contains(a) == true)
            {

                textBox4.Text = b;

            }

i haven't manage to step into the if statement. am i doing something wrong?

code is okay but the

textBox4.Text = b;

code in if statement doesnt work even if matches

data type?

like string?

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;

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        int x = 1;

        public Form1()
        {
           
           

                InitializeComponent();

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
  
                 
               
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            int y;
            string a, b, c;

            a=textBox1.Text;
            y = x;
            c = y.ToString() + "   ->";
            b = c + a;
            listBox1.Items.Add(b);
          
            x++;
            textBox1.Clear();
          

            
        }

        private void button2_Click(object sender, EventArgs e)
        {
        
        
            listBox1.Items.RemoveAt(x-2);
            x--;



         

          
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string a;
            string b;

            a = textBox3.Text;
            b = x.ToString();
            if (listBox1.Items.Contains(a) == true)
            {

                textBox4.Text = b;

            }
            

        }

       

        
    }
}

Edited 6 Years Ago by anerchy: n/a

if u run application and directly press button3 then textBox4.Text = 1 it shows
and if after runing you used button1 first and then press button3 and the textbox4.text=2 try this to case and reply and reoly with your senario

I found the problem

here;

a=textBox1.Text;
y = x;
c = y.ToString() + " ->";
b = c + a;
because of that + " ->" , the strings didnt match.

thanks for help, anyway
full code:

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;

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        int x = 1;

        public Form1()
        {



            InitializeComponent();

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {



        }

        private void button1_Click(object sender, EventArgs e)
        {

            int y;
            string a;




            a = textBox1.Text;
            y = x;


            listBox1.Items.Add(a);

            x++;
            textBox1.Clear();



        }

        private void button2_Click(object sender, EventArgs e)
        {


            listBox1.Items.RemoveAt(x - 2);
            x--;






        }

        private void button3_Click(object sender, EventArgs e)
        {
            string a;
            string b = ( "matched" );
            string c = ("no match for this");
           

            a = textBox3.Text;

            listBox1.Items.ToString();

            if (listBox1.Items.Contains(a) == true)


            {
                textBox4.Text = b;
            
            }
            else textBox4.Text = c;



        }




    }
}
This question has already been answered. Start a new discussion instead.