0

我有一个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; }
    }
4

1 回答 1

2

这是winforms还是wpf,还是asp.net?

我将开始创建一个采用这两个值的自定义控件,并显示您的复选框。然后将数据输入所述控件并将其放入您的数据网格中。

我不确定这是否与您的用例相似,但您可能想检查一下,解释如何在单个 datagridview 单元格中获取多个控件。

http://social.msdn.microsoft.com/Forums/windows/en-US/c28399bb-9d50-4a1e-b671-3dbaebb5cc69/multiple-controls-in-a-single-datagridview-cell

这可能无法完全回答您的问题,但可能会给您一个良好的开端

于 2013-09-13T09:29:29.633 回答