简体   繁体   English

在主从模式下,DevExpress GridControl出现问题

[英]Trouble with DevExpress GridControl in Master-Detail mode

I have a WinForms application with only one DevExpress GridControl inside. 我有一个WinForms应用程序,里面只有一个DevExpress GridControl。 This GridControl uses two GridViews and one relationship in Master-detail mode. 此GridControl在主从模式下使用两个GridView和一个关系。

As dataSource for gridControl I am using following class: 作为gridControl的数据源,我正在使用以下类:

public class DashboardParameter
{
    public string Name { get; set; }
    public int DataType { get; set; }
    public int ValueType { get; set; }

    public BindingList<DashboardParameterValue> Detail { get; set; }

    public DashboardParameter()
    {
        Detail = new BindingList<DashboardParameterValue>();
    }
}

public class DashboardParameterValue
{
    public string Value { get; set; }
}

Here is the code for data loading: 这是数据加载的代码:

private void MasterDetail_Load(object sender, EventArgs e)
{
    data = new BindingList<DashboardParameter>();
    var p1 = new DashboardParameter() { Name = "First", DataType = 1, ValueType = 1};
    p1.Detail.Add(new DashboardParameterValue() { Value = "Value1" });
    p1.Detail.Add(new DashboardParameterValue() { Value = "Value2" });
    var p2 = new DashboardParameter() { Name = "Second", DataType = 1, ValueType = 1 };
    p2.Detail.Add(new DashboardParameterValue() { Value = "Value3" });
    p2.Detail.Add(new DashboardParameterValue() { Value = "Value4" });
    data.Add(p1);
    data.Add(p2);

    gridControl.DataSource = data;
}

As I understand it, in this way my gridControl automatically finds master-detail relation and creating Columns for each field in class for DataSource (If AutoPopulateColumns property is true ). 据我了解,通过这种方式,我的gridControl自动查找主从关系并为DataSource类中的每个字段创建Columns(如果AutoPopulateColumns属性为true )。

Trouble: I can not change ANYTHING in my detailView Columns. 问题:我无法更改我的detailView列中的任何内容。 I dont know in wich time my dataView columns are being created. 我不知道在什么时候创建dataView列。 All of detailView properties are ignored. 所有detailView属性都将被忽略。
For example, if i changing detailView.AutoPopulateColumn = false, Columns still are being created. 例如,如果我更改detailView.AutoPopulateColumn = false,则仍在创建列。 If I create custom GridColumn gridColumn1 and add there detailView.Columns.Add(gridColumn1), it will be ignored. 如果我创建自定义GridColumn gridColumn1并在其中添加detailView.Columns.Add(gridColumn1),它将被忽略。
Only one thing i can do is using [DisplayAttribute] for changing DisplayName, Visible and so on. 我只能做的一件事就是使用[DisplayAttribute]更改DisplayName,Visible等。

Question: How must I change my code to be able to change my detailView. 问题:如何更改代码才能更改detailView。
For example, can I add Column in detailView after all auto-generated columns, or change Column type to ComboBox (using RepositoryItemComboBox). 例如,我可以在所有自动生成的列之后在detailView中添加Column,还是可以将Column类型更改为ComboBox(使用RepositoryItemComboBox)。

You can customize a detail view in the GridView.MasterRowExpanded event handler. 您可以在GridView.MasterRowExpanded事件处理程序中自定义详细信息视图。 This event is raised when a master row is expanded and a corresponding detail view is created and configured. 展开主行并创建和配置相应的详细信息视图时,将引发此事件。 To access this view, use the GridView.GetDetailView method. 要访问此视图,请使用GridView.GetDetailView方法。 Alternatively, you can handle the GridControl.ViewRegistered event. 或者,您可以处理GridControl.ViewRegistered事件。

One more solution is to create a pattern detail view and customize it at runtime or design time. 另一种解决方案是创建模式细节视图并在运行时或设计时对其进行自定义。

I suggest you to go through documentation for Working with Master-Detail Relationships in Code and Master-Detail Relationships . 我建议您阅读有关使用代码中的 主从关系主从 关系的文档。

You can create your views either based on your database structure or pragmatically by adding views and columns with their settings. 您可以基于数据库结构或通过添加视图和列及其设置来实用地创建视图。

You can customize a detail view in the GridView.MasterRowExpanded event handler. 您可以在GridView.MasterRowExpanded事件处理程序中自定义详细信息视图。 Fires immediately after a particular detail clone has become visible. 在特定细节克隆变得可见之后立即触发。 The MasterRowExpanded event fires when expanding a master row or when switching between details. 展开主行或在详细信息之间切换时,将触发MasterRowExpanded事件。

Example: 例:

//Assign a CardView to the relationship 
            CardView cardView1 = new CardView(gridControl1);
            gridControl1.LevelTree.Nodes.Add("CategoriesProducts", cardView1);
            //Specify text to be displayed within detail tabs. 
            cardView1.ViewCaption = "Category Products";

            //Hide the CategoryID column for the master View 
            gridView1.Columns["CategoryID"].VisibleIndex = -1;

            //Present data in the Picture column as Images 
            RepositoryItemPictureEdit riPictureEdit = gridControl1.RepositoryItems.Add("PictureEdit") as RepositoryItemPictureEdit;
            gridView1.Columns["Picture"].ColumnEdit = riPictureEdit;
            //Stretch images within cells.

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

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