dev gridview的單元格取值,取列名,賦值
阿新 • • 發佈:2019-01-06
1、不指定具體列名,動態取焦點所在單元格的欄位值
gridView1.FocusedValue;
gridView1.GetFocusedValue(); //Returns the focused cell value
gridView1.GetFocusedRowCellValue(gridView1.FocusedColumn);
gridView1.GetFocusedRowCellValue(gridView1.FocusedColumn.FieldName);
如按鈕1名稱取 焦點所在單元格的欄位值
simpleButton1.Text = gridView1.GetFocusedRowCellValue(gridView1.FocusedColumn.FieldName).ToString();
2、不指定具體列名,動態取焦點所在單元格的列名
gridView1.FocusedColumn.FieldName
如按鈕1名稱取 焦點所在單元格的列名
simpleButton1.Text = gridView1.FocusedColumn.FieldName.ToString();
3、單元格賦值
一種不能在單元格值變動的事件中寫,否則陷入死迴圈
int zj = Convert.ToInt32(tdQty / kunzs / zzl);
decimal sj = tdQty % (kunzs * zzl);
this.gridView1.SetRowCellValue(handle, gridView1.Columns["整件"], zj.ToString());
this.gridView1.SetRowCellValue(handle, gridView1.Columns["散件"], sj.ToString());
this.gridView1.SetRowCellValue(handle, gridView1.Columns["kunZl"], kunZl.ToString());
一種可以在單元格變動的事件中寫
int zj = Convert.ToInt32(tdQty / kunzs / zzl);
decimal sj = tdQty % (kunzs * zzl);
decimal kunZl = kunzs * zzl;
this.gridView1.GetDataRow(handle)["整件"] = zj.ToString();
this.gridView1.GetDataRow(handle)["散件"] = zj.ToString();
this.gridView1.GetDataRow(handle)["kunZl"] = zj.ToString();