I have following entity:
public class MyEntity
{
public int Id {get;set}
public Color SelectedColors
}
MyEntity has One-to-Many relation with Color enum.
[Flags]
public enum Color
{
None=1,
White=2,
Red=3,
Blue=4
}
In the other word, every myEntity object may have one or more value from Color enum:
myEntity1.Color = Color.Red | Color.White;
I saved this data using Entity Framewrok:
using (var ctx = new MyContext())
{
var entity1 = new MyEntity { SelectedColors = Color.Blue | Color.White };
ctx.MyEntities.Add(entity1);
ctx.SaveChanges();
}
and read it using following code:
using (var ctx = new MyContext())
{
var entity1 = ctx.MyEntities.Find(id);
}
I want to show the selected colors by tick on chechboxes,
I used a ListView control(WinForms project) to do this job:
listView1.CheckBoxes = true;
listView1.HeaderStyle = None;
listView1.View = List;
and used following code to show all Enum values as ListView.Items:
foreach (var value in Enum.GetValues(typeof(Color)).Cast<Color>())
{
listView1.Items.Add(new ListViewItem()
{
Name = value.ToString(),
Text = value.ToString(),
Tag = value
});
}
Is there any way to bind SelectedColors values of my query result to listView1.Items?
[Updated]
I saw a solution in this link that Nick-K inherited a new control from ListView. I think that solution isn't good for me, because the inherited control take a DataSource and a DataMember, so what should I set for DataMember in my case(SelectedColors may have more than one value)?
