KB Article A605
Visible to All Users

How to insert a new row into a detail view and populate all the foreign keys

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();

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.