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;
}
}
}
}
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