21 Mayıs 2013 Salı

Csharp - Listboxtan veri ekleme ve taşıma

Windows uygulamasında eklenen listboxlara veri ekleme ve bu eklenen verileri bir listboxtan diğerine taşıma işlemi yapma

******************************---------------------------*****************************
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 _24SubatListRemove
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //önce kodunumuz çalışacak kodlarımızı try-catch içine yazıyoruz
            //çalışacak kodlarımızı try'ın içine yazıyoruz
            //eğer hata varsa bu catch'in içine düşüyor orada hata mesajı verdiriyoruz.
            try
            {
                 if (textBox1.Text == "")
            {
                MessageBox.Show("Boş Bırakılamaz");
            }
                 else
                 {
//textbox'a girilen değeri int değişken tipini dönüştürüp
//bu değeri listbox1'e ekliyoruz. sonra textbox'ı boşaltıyoruz
                     int a = Convert.ToInt32(textBox1.Text);
                     listBox1.Items.Add(a.ToString());
                     textBox1.Text = "";
                 }
            }
            catch
            {
                //girilen değer int tipinden farklı ise uyarı mesajı ekrana geliyor.
                MessageBox.Show("interger değer giriniz");
            }
          
          
        }

        private void button2_Click(object sender, EventArgs e)
        {
//listbox1 de seçilen değeri listbox2 aktarıyoruz aynı zamanda
//listbox'ın remove komutu ile listbox1 den o seçilen değeri kaldırıyoruz
            listBox2.Items.Add(listBox1.SelectedItem);
            listBox1.Items.Remove(listBox1.SelectedItem);
        }

        private void button3_Click(object sender, EventArgs e)
        {//aynı işlemi listbox2 den seçili değeri kaldırıp listbox1 e aktarıyoruz
            listBox1.Items.Add(listBox2.SelectedItem);
            listBox2.Items.Remove(listBox2.SelectedItem);

        }

        private void button4_Click(object sender, EventArgs e)
        {
//hesapla butonuna bastığımızda, listbox2 deki değerleri sıralı ile dolaşıp for döngüsü ile
//i. sıradaki değeri alıp t değişkenine atıyoruz ve sıra ile topluyoruz.
//sonucunda listbox2 deki tüm değerleri toplayıp ekrana sonucu yazdırıyoruz.
            int y = 0;
            for (int i = 0; i < listBox2.Items.Count; i++)
            {
                y = y + Convert.ToInt32(listBox2.Items[i]);
            }
            MessageBox.Show(y.ToString());
        }
    }
}
**************************--------------------------*****************************
örnek çalışmayı buradan indirebilirsiniz: http://hotfile.com/dl/108701696/dd9989f/24SubatListRemove.rar.html

Hiç yorum yok :

Yorum Gönder

Google PageRank Checker Powered by  MyPagerank.Net