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? Please help me.
在gridcontrol中,等效代码是什么?请帮助我。
3 个解决方案
#1
9
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.
您不能直接向GridControl添加新的行,因为这只是视图的一个容器。但是,如果在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.
编辑:你可以用不同的方式访问你的视图,当然。
#2
2
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对象或其子gridview添加行。
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)。数据源属性),并通过该数据源添加/删除行。
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
.
请参阅DevExpress站点上的“绑定到数据”文档,以获得更多关于可用于GridControl的数据源的信息。
#3
0
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.
把yourgridName。RowCount-1为rowhandle插入最后一行。把gridViewMappedFileds。列["ColumnName"]给你的ColumnName。
#1
9
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.
您不能直接向GridControl添加新的行,因为这只是视图的一个容器。但是,如果在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.
编辑:你可以用不同的方式访问你的视图,当然。
#2
2
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对象或其子gridview添加行。
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)。数据源属性),并通过该数据源添加/删除行。
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
.
请参阅DevExpress站点上的“绑定到数据”文档,以获得更多关于可用于GridControl的数据源的信息。
#3
0
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.
把yourgridName。RowCount-1为rowhandle插入最后一行。把gridViewMappedFileds。列["ColumnName"]给你的ColumnName。