CheckedListBox Kullanımı[C#]

27 Şubat 2010 – 00:55 C# ta birden fazla alan seçimi yaparken checkListBox kullanırız.Örneğin kullanıcının ilgi alanlarını belirlemek isterken birden fazla alanı seçebilmesine olanak sağlarız bu gibi durumlarda checkedListBox kullanmak uygun olacaktır.Aşağıdaki uygulamada detaylı olarak checkListBox kullanımı gösterilmiştir.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); if (checkedListBox1.Items.Count == 0) { button1.Enabled = false; button3.Enabled = false; } } int i=0; private void button2_Click(object sender, EventArgs e) { i++; checkedListBox1.Items.Add(i.ToString()); if (checkedListBox1.Items.Count > 0) { button1.Enabled = true; button1.Text = "Select All"; } } int selectedIndex; private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { selectedIndex = checkedListBox1.SelectedIndex; button3.Enabled = true; } private void button3_Click(object sender, EventArgs e) { i = checkedListBox1.Items.Count-1; do { if (checkedListBox1.GetItemChecked(i)) checkedListBox1.Items.RemoveAt(i); i--; } while (i >= 0); } private void button1_Click(object sender, EventArgs e) { bool state = false; if (button1.Text.Equals("Select All")) { state = true; button1.Text = "Unselect All"; } else if (button1.Text.Equals("Unselect All")) { state = false; button1.Text = "Select All"; } for (int i = 0; i < checkedListBox1.Items.Count; i++) { checkedListBox1.SetItemChecked(i, state); } } } } |
Linkler
Etiketler: ”C#, checkedListBox”
1 yorum yapılmış
Hocam paylasımlarınız cıdden guzel ben kendı cabalarımla c# ogrenmeye calısıyorum sızın sayfanızda yararlı oluyor….
11 Aralık 2011 - 02:49