通过RadGridView,我如何才能显示详细信息

本文关键字:显示 详细信息 RadGridView 通过 | 更新日期: 2023-09-27 18:01:06

我在RadGridView中创建了一个层次关系。但这种关系并不奏效。我无法显示详细信息。我做错了什么?

如果我自动生成,所有关系都可以正常工作。但我只需要一个表中的一个字段作为详细信息。

此外:我使用VS2013 Prof.,WinForms作为UI,LINQ to SQL作为数据源。

源代码是:

    private void OpenConfigurations()
    {
          bsConfigurations.DataSource = Db.Configurations.Where(c => c.Active == true && c.CompanyId == CurrentCompany.CompanyId).Select(c => c).OrderBy(c => c.Name);
          bsConfigurationContracts.DataSource = Db.ConfigurationContracts.Where(c => c.Contract.InsurranceId == CurrentCompany.CompanyId).Select(c =>
        c).OrderBy(c => c.Contract.Name);
          GridViewRelation gvrConfigurations = new GridViewRelation();
          gvrConfigurations.ChildColumnNames.Add("ConfigurationId");
          gvrConfigurations.ChildTemplate = this.gridViewTemplate1;
          gvrConfigurations.ParentColumnNames.Add("ConfigurationId");
          gvrConfigurations.ParentTemplate = this.gvConfiguration.MasterTemplate;
          gvConfiguration.Relations.Add(gvrConfigurations);
}

在设计师:

this.gridViewTemplate1.AllowAddNewRow = false;
gridViewTextBoxColumn1.EnableExpressionEditor = false;
gridViewTextBoxColumn1.FieldName = "Contract.Name";
gridViewTextBoxColumn1.HeaderText = "Name";
gridViewTextBoxColumn1.Name = "colName";
gridViewTextBoxColumn1.Width = 250;
gridViewTextBoxColumn2.EnableExpressionEditor = false;
gridViewTextBoxColumn2.FieldName = "ConfigurationId";
gridViewTextBoxColumn2.HeaderText = "ConfigurationId";
gridViewTextBoxColumn2.IsVisible = false;
gridViewTextBoxColumn2.Name = "colConfigurationId";
this.gridViewTemplate1.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { gridViewTextBoxColumn1, gridViewTextBoxColumn2 });
this.gridViewTemplate1.DataSource = this.bsConfigurationContracts;
// 
// gvConfiguration
// 
this.gvConfiguration.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(233)))), ((int)(((byte)(240)))), ((int)(((byte)(249)))));
this.gvConfiguration.Cursor = System.Windows.Forms.Cursors.Default;
this.gvConfiguration.Dock = System.Windows.Forms.DockStyle.Fill;
this.gvConfiguration.Font = new System.Drawing.Font("Segoe UI", 8.25F);
this.gvConfiguration.ForeColor = System.Drawing.Color.Black;
this.gvConfiguration.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.gvConfiguration.Location = new System.Drawing.Point(0, 30);
// 
// 
// 
this.gvConfiguration.MasterTemplate.AllowAddNewRow = false;
this.gvConfiguration.MasterTemplate.AutoGenerateColumns = false;
gridViewTextBoxColumn3.EnableExpressionEditor = false;
gridViewTextBoxColumn3.FieldName = "Name";
gridViewTextBoxColumn3.HeaderText = "Name";
gridViewTextBoxColumn3.Name = "colName";
gridViewTextBoxColumn3.SortOrder = Telerik.WinControls.UI.RadSortOrder.Ascending;
gridViewTextBoxColumn3.Width = 250;
gridViewTextBoxColumn4.EnableExpressionEditor = false;
gridViewTextBoxColumn4.FieldName = "ConfigurationId";
gridViewTextBoxColumn4.HeaderText = "ConfigurationId";
gridViewTextBoxColumn4.IsVisible = false;
gridViewTextBoxColumn4.Name = "colConfigurationId";
this.gvConfiguration.MasterTemplate.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { gridViewTextBoxColumn3, gridViewTextBoxColumn4 });
this.gvConfiguration.MasterTemplate.DataSource = this.bsConfigurations;
sortDescriptor1.PropertyName = "colName";
this.gvConfiguration.MasterTemplate.SortDescriptors.AddRange(new Telerik.WinControls.Data.SortDescriptor[] { sortDescriptor1 });
this.gvConfiguration.MasterTemplate.Templates.AddRange(new Telerik.WinControls.UI.GridViewTemplate[] { this.gridViewTemplate1 });
this.gvConfiguration.Name = "gvConfiguration";
this.gvConfiguration.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.gvConfiguration.ShowGroupPanel = false;
this.gvConfiguration.Size = new System.Drawing.Size(1098, 72);
this.gvConfiguration.TabIndex = 4;
this.gvConfiguration.Text = "radGridView1";
this.gvConfiguration.CellDoubleClick += new Telerik.WinControls.UI.GridViewCellEventHandler(this.gvConfiguration_CellDoubleClick);

通过RadGridView,我如何才能显示详细信息

解决方案是在必须添加列名而不是字段名的关系中。

所以这是正确的代码:

GridViewRelation gvrConfigurations = new GridViewRelation();
          gvrConfigurations.ChildColumnNames.Add("colConfigurationId");
          gvrConfigurations.ChildTemplate = this.gridViewTemplate1;
          gvrConfigurations.ParentColumnNames.Add("colConfigurationId");
          gvrConfigurations.ParentTemplate = this.gvConfiguration.MasterTemplate;
          gvConfiguration.Relations.Add(gvrConfigurations);