Im creating a line
object which is an entity it has a Tags
navigation property which I also want to set. I want to get this tags collection from a datagridview bound to Tag
objects :
dgvTags.DataSource = _rs.Tags.Where(x => x.TagGroup.Name == "All Reasons").OrderBy(x => x.Name);
Code with issue :
Line l = new Line
{
Part = o.Part,
Description = desc,
Price = o.Price.Value,
InvoiceNo = o.InvoiceNo,
Cost = o.Cost.Value,
Comments = txtComment.Text,
Tags = dgvTags.SelectedRows as List<Tag> // <--- needs work here
};
The line is showing an error :
Error 5 Cannot convert type 'System.Windows.Forms.DataGridViewSelectedRowCollection' to 'System.Collections.Generic.List' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion C:\SVN\RS\fAddLines.cs 142 15 RS
Is there a correct way of doing this?
UPDATE:
Ive been able to acheive the desired result with the code below, but still looking for the correct way to do it :
foreach (DataGridViewRow r in dgvTags.SelectedRows)
{
l.Tags.Add(r.DataBoundItem as Tag);
}