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

拟墨画扇 提交于 2019-12-24 01:39:18

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/19062111/how-to-add-new-line-of-row-in-devexpress-gridcontrolwinforms-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!