简体   繁体   English

实体框架,多个值1个单元格/ Datagridview c#

[英]Entity Framework, Multiple values 1 cell/ Datagridview c#

I have a datagridview and I need to somehow have 2 values in my database in the same cell. 我有一个datagridview,我需要在同一个单元格中的数据库中以某种方式获得2个值。

I need to have 2 checkboxes in the same column which are currently smallints in the database. 我需要在同一列中有2个复选框,这些复选框当前是数据库中的smallints。

I am using entity framework if that helps? 如果有帮助,我正在使用实体框架?

Also I need to be able to store these values back to the database! 此外,我需要能够将这些值存储回数据库!

I'm not entirely sure where to start so any pointers would be brilliant! 我不完全确定从哪里开始所以任何指针都会很精彩!

Code is a basic EF with a DataBindingProjection class, 代码是一个带有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; }
    }

Is this winforms or wpf, or asp.net? 这是winforms还是wpf,还是asp.net?

I would start be creating a custom control that takes these two values, and displays your checkboxes. 我将开始创建一个自定义控件来获取这两个值,并显示您的复选框。 Then feeding the data into said control and putting that into your datagrid. 然后将数据提供给所述控件并将其放入您的数据网格中。

I'm not sure if this is similar to your usecase but you might want to check this out, explaning how to get mulitple controls in a single datagridview cell. 我不确定这是否与您的用例相似,但您可能想要检查一下,解释如何在单个datagridview单元格中获取多个控件。

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

This may not answer your question completely but might give you a head start 这可能无法完全回答您的问题,但可能会给您一个良好的开端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM