Metainformationen zur Seite
  •  
Diese Seite dürfen sie nicht sehen.

Dies ist eine alte Version des Dokuments!


CheckListBox mit nicht veränderbaren Items

Um in einer Listbox unveränderliche Items darzustellen habe ich in der Dialogklasse zwei Funktionen hinzugefügt:

    SetReadonlyItem (int index, CheckState value)
    addChkListBoxItem_ItemChanged(object sender, ItemCheckEventArgs e) 

Im Konstruktor wird die addChkListBoxItem_ItemChanged dem ItemCheck-Event des CheckedListBox Objekts angemeldet.

Die SetReadonlyItem wird verwendet um ReadOnlyItems zu setzen und ändern.

        public partial class SelectDialog : Form
        {
            private List<int> readOnlyItems = new List<int>();
 
            public SelectDialog()
            {
                InitializeComponent();
                this.add_chkListBox.ItemCheck += this.addChkListBoxItem_ItemChanged;
            }
 
 
            /// <summary>
            /// Set an CheckListBox item to an readonly item.
            /// CheckState of readonly items can be changed programmatically but not within dialogbox
            /// </summary>
            /// <param name="index">Index of Item</param>
            /// <param name="value">CheckState of item</param>
            public void SetReadonlyItem (int index, CheckState value)
            {
                this.add_chkListBox.ItemCheck -= this.addChkListBoxItem_ItemChanged;
                this.add_chkListBox.SetItemCheckState(index, value);
                this.add_chkListBox.ItemCheck += this.addChkListBoxItem_ItemChanged;
                if (!this.readOnlyItems.Contains(index))
                {
                    this.readOnlyItems.Add(index);
                }
            }
 
            private void addChkListBoxItem_ItemChanged(object sender, ItemCheckEventArgs e)
            {
                 if (readOnlyItems.Contains(e.Index))
                 {
                     e.NewValue = e.CurrentValue;
                 }
            }
        }
Artikel Info
Stand
Fertig
Version14.1113
Kategorien

Anleitung

,

Programmieren

Programmiersprache
ProgrammierspracheC-Sharp

Diskussion

Geben Sie Ihren Kommentar ein. Wiki-Syntax ist zugelassen:
Bitte übertragen Sie die Buchstaben in das Eingabefeld.