Titov S.P.
Titov S.P.

Reputation: 75

Trouble with DevExpress GridControl in Master-Detail mode

I have a WinForms application with only one DevExpress GridControl inside. This GridControl uses two GridViews and one relationship in Master-detail mode.

As dataSource for gridControl I am using following class:

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).

Trouble: I can not change ANYTHING in my detailView Columns. I don't know in which time my dataView columns are being created. All of detailView properties are ignored.
For example, if I changing detailView.AutoPopulateColumn = false, Columns still are being created. If I create custom GridColumn gridColumn1 and add there detailView.Columns.Add(gridColumn1), it will be ignored.
Only one thing I can do is using [DisplayAttribute] for changing DisplayName, Visible and so on.

Question: How must I change my code to be able to change my detailView.
For example, can I add Column in detailView after all auto-generated columns, or change Column type to ComboBox (using RepositoryItemComboBox).

Upvotes: 0

Views: 3596

Answers (2)

Niranjan Singh
Niranjan Singh

Reputation: 18290

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. Fires immediately after a particular detail clone has become visible. The MasterRowExpanded event fires when expanding a master row or when switching between details.

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.

Upvotes: 0

Svetlana
Svetlana

Reputation: 421

You can customize a detail view in the GridView.MasterRowExpanded event handler. 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. Alternatively, you can handle the GridControl.ViewRegistered event.

One more solution is to create a pattern detail view and customize it at runtime or design time.

Upvotes: 0

Related Questions