bouchnina

c sharp listbox recherche

Mar 18th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Collections;
  11.  
  12. namespace TriListe
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.         int i,j;
  21.  
  22.         private void Form1_Load(object sender, EventArgs e)
  23.         {
  24.  
  25.         }
  26.  
  27.         private void textBox1_KeyDown(object sender, KeyEventArgs e)
  28.         {
  29.             if (e.KeyData == Keys.Enter)
  30.             {
  31.                 listBox1.Items.Add(textBox1.Text);
  32.                 textBox1.Clear();
  33.  
  34.             }
  35.         }
  36.  
  37.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  38.         {
  39.  
  40.         }
  41.  
  42.         private void Rechercher(object sender, EventArgs e)
  43.         {
  44.             for (i = 0; i < listBox1.Items.Count; i++)
  45.             {
  46.                 string s = listBox1.Items[i].ToString();
  47.  
  48.                 if (s.Contains(textBox2.Text))
  49.                 {
  50.                     MessageBox.Show("Element trouvé " + i);
  51.  
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment