How Change number format of DevExpress Gridcontrol detail view

How to change number format of DevExpress Gridcontrol master-detail view

How to change grid control's column format ? We already covered that topic, for reference please not the recommended post section.

Changing the number format in a master-detail section .

To accomplish the task we need to create an event handler for MasterRowExpanded. From the event we can access and change the desired number format for specific column.

Create the event

In the code window create a event handler as follows.

    private void gridView1_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
        {
            GridView detailView = gridView1.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
            if (detailView != null)
            {
                // Customize the detail view here
                detailView.Columns["Amount"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                detailView.Columns["Amount"].DisplayFormat.FormatString="c2";
             
            }
        }

Using the GetDetailView method we can access the detail view and change the desired column format.

Subscribing to the Event

In the load section subscribe to the event. as follows.

 private void VoucherLists_Load(object sender, EventArgs e)
        {                 
                (gridView1 as GridView).MasterRowExpanded += gridView1_MasterRowExpanded;
}

devexpress
gridcontrol
gridcontrol-format

Write your comment