Binding enabled property from CheckedListBox.Items - Winforms

I'm relatively new to winforms programming, coming from ASP.NET, and I'm struggling to bundle things like the "Enabled" field from the checklistbox.items list.

For example, I have:

class A
{
    public string Name {get;set;}
    public bool Enabled {get; set;}
}

Then I create the elements of list A and snap to the marked list.

List<A> aList = new List<A>(
    new A{Name="Item1", Enabled=true}, 
    new A{Name="Item2", Enabled=false} );

CheckedListBox.DataSource = aList;
CheckedListBox.DisplayMember = "Name";

Finally, how do I make elements with "Enabled == false" to show how disabled in the list of marks?

Of course, I will need to do the same with the checked property, but for simplicity I do not add it to the example.

Thank,

John

+3
source share
1 answer

You cannot execute this rich data binding using WinForms CheckedListBox.

DataSource, DisplayMember ValueMember, ( Enabled Checked)

, :

checkedListBox.DataSource = aList; 
checkedListBox.DisplayMember = "Name";
checkedListBox.ValueMember = "Name";

, .

, ( , ) - CheckedListBox, - .

- , .

+1

Source: https://habr.com/ru/post/1793982/


All Articles