一、gridview 新增一行有两种:
1.gridView.AddNewRow()然后在gridView_InitNewRow事件里面填写新添加行的数据。
private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e) //添加一行后触发事件,赋值
{
ColumnView View = sender as ColumnView;
View .SetRowCellValue(e.RowHandle, "UserName", addusername);
View .SetRowCellValue(e.RowHandle, "LoginName", addloginname);
gridView1.FocusedRowHandle = e.RowHandle;
}
2. 直接在 数据源里面赋值,及datatable里面。
datatable table = new datatable();
gridcontrid.datasource = table;
DataRow newrow = usertable.NewRow();
newrow["UserName"] = addusername;
newrow["LoginName"] = addloginname;
usertable.Rows.Add(newrow);
gridView1.FocusedRowHandle = gridView1.RowCount - 1;
二、gridview界面上的修改删除操作
修改:gridView1.SetFocusedRowCellValue("UserName",editForm.returuserName);
删除:gridView1.DeleteRow(deletehandle[i]); //删除一行
gridView1.DeleteSelectedRows(); //删除选中的所有行
三 gridview属性设置
列头禁止移动 : 设置gridView1.OptionsCustomization.AllowColumnMoving = false;
列头禁止排序: 设置gridView1.OptionsCustomization.AllowSort = false;.
隐藏最上面的GroupPanel :gridView1.OptionsView.ShowGroupPanel=false;
数据只读 :gridView1.OptionsBehavior.Editable=false;
只读可拷贝:
ColumnViewOptionsBehavior.Editable = True
OptionsColumn.AllowEdit = True
OptionsColumn.ReadOnly = True
可编辑:
ColumnViewOptionsBehavior.Editable = True
OptionsColumn.AllowEdit = True
OptionsColumn.ReadOnly = False
得到单元格数据(0行0列):
string ss=gridView1.GetRowCellDisplayText(0,gridView1.Columns[0]);
string ss = gridView1.GetRowCellValue(0, gridView1.Columns[0]);
设置单元格数据(将0行0列的单元格赋值123):
gridView1.SetRowCellValue(0, gridView1.Columns[0],"123");
dev 控件之 gridcontrid 应用,布布扣,bubuko.com