二、获取表格数据
int selectRow = gridView1.GetSelectedRows()[0]; string id = this.gridView1.GetRowCellValue(selectRow, "id").ToString();
string colValue = this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, this.gridView1.Columns["qty"]).ToString(); var s = gridView1.GetDataRow(e.RowHandle)["列名"].ToString(); //当前单元格所在行的数据
注意 e.value 获取当前编辑的值,上面对编辑单元格无效,只可以触发 GridView1_CellValueChanging 事件
'设置单元格中的值 GridView.SetRowCellValue(GridView.FocusedRowHandle, GridView.Columns("列名"),"要设置的值") '得到单元格中的值 Me.GridView_Analysis.GetRowCellValue(GridView.FocusedRowHandle, "列名") '数据表中当前单元格的值 DataSet.Tables(0).Rows(GridView.FocusedRowHandle).Item("列名")
一、Dev单元格只允许输入数字
private void GridView1_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (Convert.ToInt32(this.gridView1.GetDataRow(e.RowHandle)["qty"]) < e.Value.ToInt()) { this.gridView1.SetRowCellValue(e.RowHandle, "pick_qty", Convert.ToInt32(this.gridView1.GetDataRow(e.RowHandle)["qty"])); this.gridView1.SetRowCellValue(e.RowHandle, "qty-pick_qty", 0); } else if (e.Value.ToString() == "") { this.gridView1.SetRowCellValue(e.RowHandle, "pick_qty", 0); this.gridView1.SetRowCellValue(e.RowHandle, "qty-pick_qty", Convert.ToInt32(this.gridView1.GetDataRow(e.RowHandle)["qty"])); } else { this.gridView1.SetRowCellValue(e.RowHandle, "qty-pick_qty", Convert.ToInt32(this.gridView1.GetDataRow(e.RowHandle)["qty"]) - e.Value.ToInt()); } } private void GridData_EditorKeyPress(object sender, KeyPressEventArgs e) { GridControl grid = sender as GridControl; gridView1_KeyPress(grid.FocusedView, e); } private void gridView1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '' || e.KeyChar == ' ') { e.Handled = false; return; } GridView view = sender as GridView; string s = "0123456789"; if (view.FocusedColumn.FieldName == "pick_qty" && s.LastIndexOf(e.KeyChar) >= 0) { e.Handled = false; } else e.Handled = true; }