简体   繁体   中英

How to add new line of row in devexpress gridcontrol?(WinForms C#)

I want to add a new line of row when pressing a button. In datagridview it would be: datagridview1.Rows.Add()

What is the equivalent code for that in gridcontrol? Please help me.

You cannot add a new row directly to your GridControl , since this is just a container for the views. However, if you're using a GridView inside your GridControl (or any other descendant of ColumnView), you can add a new row using AddNewRow() method.

(myGridcontrol.MainView as DevExpress.XtraGrid.Views.Grid.GridView).AddNewRow();

Link to documentation

EDIT: You can access your view in a different way, of course.

The DevExpress GridControl must always be bound to a datasource: you cannot add rows directly to the GridControl object or its child GridViews .

Instead, you must bind your GridControl to a data source (via the GridControl.DataSource property), and add/remove rows via this data source.

See the 'Binding To Data' documentation at the DevExpress site for more information on the kinds of data sources that can be used with a GridControl .

You can use AddNewRow to add new row and SetRowCellValue to insert value to that row.

yourgridViewName.AddNewRow();
yourgridViewName.SetRowCellValue(rowhandle,columnName,value);
gridViewMappedFileds.UpdateCurrentRow();

Put yourgridName.RowCount-1 for rowhandle to insert the row at last.Put gridViewMappedFileds.Columns["ColumnName"] to give your columnname.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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