ListBox ve ComboBox Kullanımını Beraber İnceleyelim..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox3.Items.Add(“Doktor”);
comboBox3.Items.Add(“Ogretmen”);
comboBox3.Items.Add(“Memur”);
comboBox3.Items.Add(“Iscı”);
comboBox3.Items.Add(“Öğrenci”);
comboBox3.Items.Add(“Polıs”);
comboBox3.Items.Add(“Avukat”);
comboBox3.Items.Add(“Esnaf”);
comboBox4.Items.Add(“Evlı”);
comboBox4.Items.Add(“Bekar”);
comboBox4.Items.Add(“Dul”);
}
private void button1_Click(object sender, EventArgs e)
{
int a, i;
listBox5.Items.Clear();
listBox1.Items.Add(textBox1.Text);
listBox2.Items.Add(textBox2.Text);
if (comboBox3.Text != “Meslek”)
listBox3.Items.Add(comboBox3.Text);
else
listBox3.Items.Add(“”);
if (comboBox4.Text!=”M.Hal”)
listBox4.Items.Add(comboBox4.Text);
else
listBox4.Items.Add(“”);
a = listBox1.Items.Count;
for (i = 1; i <= a; i++)
listBox5.Items.Add(Convert.ToString(i));
}
private void button3_Click(object sender, EventArgs e)
{
int b;
b = Convert.ToInt32(listBox1.SelectedIndex);
listBox1.Items[b] = textBox3.Text;
listBox2.Items[b] = textBox4.Text;
listBox3.Items[b] = textBox5.Text;
listBox4.Items[b] = textBox6.Text;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32(listBox1.SelectedIndex);
listBox2.SelectedIndex = a;
listBox3.SelectedIndex = a;
listBox4.SelectedIndex = a;
textBox3.Text = Convert.ToString(listBox1.SelectedItem);
textBox7.Text = Convert.ToString(listBox1.SelectedIndex);
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32(listBox2.SelectedIndex);
listBox1.SelectedIndex = a;
listBox3.SelectedIndex = a;
listBox4.SelectedIndex = a;
textBox4.Text = Convert.ToString(listBox2.SelectedItem);
textBox7.Text = Convert.ToString(listBox1.SelectedIndex);
}
private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32(listBox3.SelectedIndex);
listBox1.SelectedIndex = a;
listBox2.SelectedIndex = a;
listBox4.SelectedIndex = a;
textBox5.Text = Convert.ToString(listBox3.SelectedItem);
textBox7.Text = Convert.ToString(listBox1.SelectedIndex);
}
private void listBox4_SelectedIndexChanged(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32(listBox4.SelectedIndex);
listBox1.SelectedIndex = a;
listBox3.SelectedIndex = a;
listBox2.SelectedIndex = a;
textBox6.Text = Convert.ToString(listBox4.SelectedItem);
textBox7.Text = Convert.ToString(listBox1.SelectedIndex);
}
private void button2_Click(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32(listBox1.SelectedIndex);
listBox1.Items.RemoveAt(a);
listBox2.Items.RemoveAt(a);
listBox3.Items.RemoveAt(a);
listBox4.Items.RemoveAt(a);
}
private void button4_Click(object sender, EventArgs e)
{
string ad;
int i, j, a;
a = listBox1.Items.Count – 1;
for (i = 0; i <= a – 1; i++)
for (j = i + 1; j <= a; j++)
if (String.Compare(Convert.ToString(listBox1.Items[i]), (Convert.ToString(listBox1.Items[j]))) == 1)
{
ad = Convert.ToString(listBox1.Items[i]);
listBox1.Items[i] = listBox1.Items[j];
listBox1.Items[j] = ad;
ad = Convert.ToString(listBox2.Items[i]);
listBox2.Items[i] = listBox2.Items[j];
listBox2.Items[j] = ad;
ad = Convert.ToString(listBox3.Items[i]);
listBox3.Items[i] = listBox3.Items[j];
listBox3.Items[j] = ad;
ad = Convert.ToString(listBox4.Items[i]);
listBox4.Items[i] = listBox4.Items[j];
listBox4.Items[j] = ad;
}
}
}
}