我有一个datagridview,我需要在同一个单元格中的数据库中以某种方式获得2个值。
我需要在同一列中有2个复选框,这些复选框当前是数据库中的小写。
如果有帮助,我正在使用实体框架吗?
此外,我需要能够将这些值存储回数据库!
我不完全确定从哪里开始,所以任何指针都会很精彩!
代码是一个带有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; }
}
答案 0 :(得分:2)
这是winforms还是wpf,还是asp.net?
我将开始创建一个带有这两个值的自定义控件,并显示您的复选框。然后将数据提供给所述控件并将其放入数据网格中。
我不确定这是否与您的用例相似,但您可能想要检查一下,解释如何在单个datagridview单元格中获取多个控件。
这可能不会完全回答你的问题,但可能会给你一个良好的开端