Search code examples
c#listdata-bindingdistinct-values

How to get a dynamic list of distinct property values of a list?


I am trying to bind a ComboBox control to a list of strings extracted from a list of custom objects.

Here is the object I'm using :

public class Operation
{
    public DateTime ValueDate { get; set; }
    public int Amount { get; set; }
    public string Category { get; set; }
}

What I'm trying to do is binding the combo box used to input a new Operation's Category to the list of distinct categories already existing in a list of Operations.

Example :

List of Operations :

{04/12/2010, 100, "Home"}
{05/12/2010, 100, "Home"}
{05/12/2010, 200, "Entertainment"}

Available in the auto-complete list of the combobox : "Home", "Entertainment".

Currently, I am able to get a static list of the available categories existing in the list, but I am unable to get the list updated when I add a new Operation to the existing list.


Solution

  • You will need to unbind and rebind your list for refresh.