我有一个datagridview,我需要以某种方式在同一个单元格中的数据库中有2个值。
我需要在同一列中有 2 个复选框,这些复选框当前是数据库中的 smallints。
如果有帮助,我正在使用实体框架?
我还需要能够将这些值存储回数据库!
我不完全确定从哪里开始,所以任何指针都会很棒!
代码是带有 DataBindingProjection 类的基本 EF,
private void HtReports_Load(object sender, EventArgs e)
{
dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
fmsEntities context = new fmsEntities();
var query = (from f in context.funerals
where f.IsPencil == 0
join d in context.deceaseddetails on f.DeceasedID equals d.ID
join i in context.funeralservices on f.ID equals i.FuneralID
where i.IsAlternative == 0
join h in context.htvalues on f.HtValuesID equals h.ID
join p in context.placeofdeaths on f.PlaceOfDeathID equals p.ID
join c in context.coroners on f.CoronerID equals c.ID
let val1 = d.DateOfDeath
let val2 = d.DateOfBirth
let val3 = i.Date
orderby i.Date
select new
{
d.LastName,
d.FirstName,
val2,
val1,
f.CremOrInt,
FormsSigned1 = h.FormsSigned1 ?? 0,
FormsSigned2 = h.FormsSigned2 ?? 0,
}).ToList();
var dataobjects = query.Select(d => new DataBindingProjection
{
DeceasedName = (d.FirstName + Environment.NewLine + d.LastName),
DOBDOD = (d.val2.HasValue ? d.val2.Value.ToShortDateString() : string.Empty) + Environment.NewLine +
(d.val1.HasValue ? d.val1.Value.ToShortDateString() : string.Empty),
CremInt = d.CremOrInt
}).ToList();
dataGridView1.DataSource = dataobjects;
dataGridView1.Columns[0].HeaderText = "Last Name" + Environment.NewLine + "First Name";
dataGridView1.Columns[1].HeaderText = "DOB" + Environment.NewLine + "DOD";
dataGridView1.Columns[2].HeaderText = "Crem/Int";
}
private class DataBindingProjection
{
public string DeceasedName {get; set;}
public string DOBDOD {get; set;}
public string CremInt { get; set; }
}