Combobox ve listbox Kullanımı

Bu derste C#'de Combobox ve listbox kullanımını işleyelim.

Bu derste C#'de Combobox ve listbox kullanımını işleyelim.




using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;



namespace uygulama15

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }



        private void Form1_Load(object sender, EventArgs e)

        {



        }

        

      

        private void button1_Click(object sender, EventArgs e)

        {

            if (textBox1.Text == "") MessageBox.Show("isim giriniz!");  

            else

            {

                listBox2.Items.Add(textBox1.Text);

                listBox3.Items.Add(textBox2.Text);



                int d;

                d = listBox2.Items.Count;

                listBox1.Items.Add(d);











                if (comboBox1.Text == "meslek") listBox4.Items.Add("");

                else listBox4.Items.Add(comboBox1.Text);

                if (comboBox2.Text == "medeni hal") listBox5.Items.Add("");

                else

                    listBox5.Items.Add(comboBox2.Text);

            }



        }



     



      



        private void listBox1_Click(object sender, EventArgs e)

        {

            int b;

            b = listBox1.SelectedIndex;

            listBox2.SelectedIndex = b;

            listBox3.SelectedIndex = b;

            listBox4.SelectedIndex = b;

            listBox5.SelectedIndex = b;



            textBox3.Text = Convert.ToString(b);

            textBox4.Text = Convert.ToString(listBox2.SelectedItem);

            textBox5.Text = Convert.ToString(listBox3.SelectedItem);

            textBox6.Text = Convert.ToString(listBox4.SelectedItem);

            textBox7.Text = Convert.ToString(listBox5.SelectedItem);

 



         

            

        }



        private void listBox2_Click(object sender, EventArgs e)

        {

            int b;

            b = listBox2.SelectedIndex;

            listBox1.SelectedIndex = b;

            listBox3.SelectedIndex = b;

            listBox4.SelectedIndex = b;

            listBox5.SelectedIndex = b;



            textBox3.Text = Convert.ToString(b + 1);

            textBox4.Text = Convert.ToString(listBox2.SelectedItem);

            textBox5.Text = Convert.ToString(listBox3.SelectedItem);

            textBox6.Text = Convert.ToString(listBox4.SelectedItem);

            textBox7.Text = Convert.ToString(listBox5.SelectedItem);

        }



        private void listBox3_Click(object sender, EventArgs e)

        {

            int b;

            b = listBox3.SelectedIndex;

            listBox1.SelectedIndex = b;

            listBox2.SelectedIndex = b;

            listBox4.SelectedIndex = b;

            listBox5.SelectedIndex = b;



            textBox3.Text = Convert.ToString(b + 1);

            textBox4.Text = Convert.ToString(listBox2.SelectedItem);

            textBox5.Text = Convert.ToString(listBox3.SelectedItem);

            textBox6.Text = Convert.ToString(listBox4.SelectedItem);

            textBox7.Text = Convert.ToString(listBox5.SelectedItem);

        }



        private void listBox4_Click(object sender, EventArgs e)

        {

                 int b;

            b = listBox4.SelectedIndex;

            listBox2.SelectedIndex = b;

            listBox3.SelectedIndex = b;

            listBox1.SelectedIndex = b;

            listBox5.SelectedIndex = b;



            textBox3.Text = Convert.ToString(b + 1);

            textBox4.Text = Convert.ToString(listBox2.SelectedItem);

            textBox5.Text = Convert.ToString(listBox3.SelectedItem);

            textBox6.Text = Convert.ToString(listBox4.SelectedItem);

            textBox7.Text = Convert.ToString(listBox5.SelectedItem);

        }



        private void listBox5_Click(object sender, EventArgs e)

        {

            int b;

            b = listBox5.SelectedIndex;

            listBox2.SelectedIndex = b;

            listBox3.SelectedIndex = b;

            listBox4.SelectedIndex = b;

            listBox1.SelectedIndex = b;



            textBox3.Text = Convert.ToString(b + 1);

            textBox4.Text = Convert.ToString(listBox2.SelectedItem);

            textBox5.Text = Convert.ToString(listBox3.SelectedItem);

            textBox6.Text = Convert.ToString(listBox4.SelectedItem);

            textBox7.Text = Convert.ToString(listBox5.SelectedItem);

           

        }



        private void button2_Click(object sender, EventArgs e)

        {

            int c,h,k;

            c=listBox1.SelectedIndex;

            listBox1.Items.RemoveAt(c);

            listBox2.Items.RemoveAt(c);

            listBox3.Items.RemoveAt(c);

            listBox4.Items.RemoveAt(c);

            listBox5.Items.RemoveAt(c);



            textBox3.Text="";

            textBox3.Text="";

            textBox4.Text="";

            textBox5.Text="";

            textBox6.Text="";

            textBox7.Text = "";



            listBox1.Items.Clear();

            h  = listBox2.Items.Count;



            for (k = 1; k <= h; k++) 

            listBox1.Items.Add(k.ToString());







        }



        private void button3_Click(object sender, EventArgs e)

        {

            int i;

            i = listBox1.SelectedIndex;

            listBox2.Items = textBox4.Text;

            listBox3.Items = textBox5.Text;

            listBox4.Items = textBox6.Text;

            listBox5.Items = textBox7.Text;



        

        }



       



        private void button6_Click(object sender, EventArgs e)

        {

            listBox1.SelectedIndex = 0;

            listBox2.SelectedIndex = 0;

            listBox3.SelectedIndex = 0;

            listBox4.SelectedIndex = 0;

            listBox5.SelectedIndex = 0;



            textBox3.Text = Convert.ToString(listBox1.SelectedItem);

            textBox4.Text = Convert.ToString(listBox2.SelectedItem);

            textBox5.Text = Convert.ToString(listBox3.SelectedItem);

            textBox6.Text = Convert.ToString(listBox4.SelectedItem);

            textBox7.Text = Convert.ToString(listBox5.SelectedItem);



        }



        private void button7_Click(object sender, EventArgs e)

        {

            int s;

            s = listBox1.Items.Count;



            listBox1.SelectedIndex = s-1;

            listBox2.SelectedIndex = s-1;

            listBox3.SelectedIndex = s-1;

            listBox4.SelectedIndex = s-1;

            listBox5.SelectedIndex = s-1;



            textBox3.Text = Convert.ToString(listBox1.SelectedItem);

            textBox4.Text = Convert.ToString(listBox2.SelectedItem);

            textBox5.Text = Convert.ToString(listBox3.SelectedItem);

            textBox6.Text = Convert.ToString(listBox4.SelectedItem);

            textBox7.Text = Convert.ToString(listBox5.SelectedItem);









        }



        private void button4_Click(object sender, EventArgs e)

        {

            int f,n;

            f = listBox1.Items.Count;

            n = listBox1.SelectedIndex;

            if ((f - 1) == n) MessageBox.Show("son kayıttasınız");

            else

             listBox1.SelectedIndex=n+1;

             listBox2.SelectedIndex=n+1;

             listBox3.SelectedIndex=n+1;

             listBox4.SelectedIndex=n+1;

             listBox5.SelectedIndex=n+1;



             textBox3.Text = Convert.ToString(listBox1.SelectedItem);

             textBox4.Text = Convert.ToString(listBox2.SelectedItem);

             textBox5.Text = Convert.ToString(listBox3.SelectedItem);

             textBox6.Text = Convert.ToString(listBox4.SelectedItem);

             textBox7.Text = Convert.ToString(listBox5.SelectedItem);





        



        }



        private void button5_Click(object sender, EventArgs e)

        {



            int  n;

           

            n = listBox1.SelectedIndex;

            if ( n== 0) MessageBox.Show("ilk kayıttasınız");

            else

                listBox1.SelectedIndex = n- 1;

            listBox2.SelectedIndex = n - 1;

            listBox3.SelectedIndex = n - 1;

            listBox4.SelectedIndex = n - 1;

            listBox5.SelectedIndex = n - 1;



            textBox3.Text = Convert.ToString(listBox1.SelectedItem);

            textBox4.Text = Convert.ToString(listBox2.SelectedItem);

            textBox5.Text = Convert.ToString(listBox3.SelectedItem);

            textBox6.Text = Convert.ToString(listBox4.SelectedItem);

            textBox7.Text = Convert.ToString(listBox5.SelectedItem);

        }



        private void button8_Click(object sender, EventArgs e)

        {

            textBox1.Text = "";

            textBox2.Text = "";

            comboBox1.Text = "";

            comboBox2.Text = "";

        }

        }



      



       

    }

  • Etiketler;
Yorum Yaz

Yorum yazabilmek için üye girişi yapmanız gerekiyor!

Yukarı Git