add new row gridview devexpress c# code example
Example: c# devexpress add new row at specific olumn
using DevExpress.XtraGrid;
using System;
using System.ComponentModel;
namespace SampleGridApplication {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
this.Load += Form1_Load;
gridView1.OptionsBehavior.AllowAddRows = DevExpress.Utils.DefaultBoolean.False;
}
private void Form1_Load(object sender, EventArgs e) {
gridControl1.DataSource = SampleDS();
}
private void button1_Click(object sender, EventArgs e) {
gridView1.AddNewRow();
gridView1.SetRowCellValue(GridControl.NewItemRowHandle, gridView1.Columns["Name"], "Please enter new value");
}
public BindingList<Entry> SampleDS() {
BindingList<Entry> ds = new BindingList<Entry>();
ds.Add(new Entry("One", 1));
ds.Add(new Entry("Two", 2));
ds.Add(new Entry("Three", 3));
ds.AllowNew = true;
return ds;
}
}
public class Entry {
public Entry() { }
public Entry(string name, Int32 id) {
Name = name; ID = id;
}
public string Name { get; set; }
public Int32 ID { get; set; }
}
}