Crystal Mae Perez
Crystal Mae Perez

Reputation: 23

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.

Upvotes: 2

Views: 42688

Answers (3)

Raz Mahato
Raz Mahato

Reputation: 915

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.

Upvotes: 0

Marko Juvančič
Marko Juvančič

Reputation: 5890

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.

Upvotes: 9

pixelbadger
pixelbadger

Reputation: 1596

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.

Upvotes: 2

Related Questions