Description:
I allow my end-users to insert a new record into a detail view. However, I would like all detail key fields to be filled with corresponding data from a master data source. How can I achieve this?
Answer:
This can be implemented if you add a new record using the view's AddNewRow method. If you wish to insert a record into a DetailView, you should access the corresponding Clone View (a detail view object which is always created when a master row is expanded and which actually handles the data shown in it). Please review the "Pattern and Clone Views" topic from the grid documentation to learn more about this concept. To determine the View currently focused in the GridControl, you should use the gridControl1.KeyboardFocusView property. Here is some sample code showing how to add a new row to the currently focused View:
C#(gridControl1.KeyboardFocusView as DevExpress.XtraGrid.Views.Grid.GridView).AddNewRow();
If you need to determine a detail View for a particular master row, please use the master view's GetDetailView method:
C#DevExpress.XtraGrid.Views.Grid.GridView view = gridView1.GetDetailView(gridView1.FocusedRowHandle, 0) as DevExpress.XtraGrid.Views.Grid.GridView;
if (view != null)
view.AddNewRow();