[英]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()
在datagridview中它将是:datagridview1.Rows.Add()
What is the equivalent code for that in gridcontrol? gridcontrol中的等效代码是什么? Please help me.
请帮我。
You cannot add a new row directly to your GridControl
, since this is just a container for the views. 您无法直接向
GridControl
添加新行,因为这只是视图的容器。 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. 但是,如果您在
GridControl
(或ColumnView的任何其他后代)中使用GridView
,则可以使用AddNewRow()
方法添加新行。
(myGridcontrol.MainView as DevExpress.XtraGrid.Views.Grid.GridView).AddNewRow();
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
. DevExpress
GridControl
必须始终绑定到数据源:您不能将行直接添加到GridControl
对象或其子GridViews
。
Instead, you must bind your GridControl
to a data source (via the GridControl.DataSource
property), and add/remove rows via this data source. 相反,您必须将
GridControl
绑定到数据源(通过GridControl.DataSource
属性),并通过此数据源添加/删除行。
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
. 有关可与
GridControl
一起使用的数据源类型的更多信息,请参阅DevExpress站点上的“绑定到数据”文档。
You can use AddNewRow to add new row and SetRowCellValue to insert value to that row. 您可以使用AddNewRow添加新行和SetRowCellValue以向该行插入值。
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. 将rowgle的yourgridName.RowCount-1放在最后插入行。输入gridViewMappedFileds.Columns [“ColumnName”]以给出您的列名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.