Turbotrdlo Turbotrdlo - 9 months ago 42
C# Question

CheckedListBox - how to set which parameter of an object to display?

I have a problem with CheckedListBox.
I have a list of objects:

private WinPcapDeviceList deviceList = WinPcapDeviceList.Instance;

This contains WinPcapDevice objects.
I wanted to add the list as a datasource for the ChecklistBox

CheckList.DataSource = devices;

When i start the program the output is not very helpful for user as it looks something like this: checkedlistbox with WinPcapDeviceList as datasource

I want it to look like this: checkedlistbox with description of devices

So in the list is only the description of the devices, here's how you can get the description:


How can i set which property of the object will be diplayed?

Answer Source

You have to indicate what property of the source item you want to display using the "DisplayMember" property of CheckedLisbox (https://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox_members(v=vs.90).aspx).

You example shows that the description comes from a method, so you will perhaps have to create a property with a getter that will call this method.

Hope this will help.