datagridview上下移動整行

2021-09-22 20:12:49 字數 1731 閱讀 3509

原位址

//方法 上移 下移 刪除 d**showprocess是乙個datagridview

private void upordownordelete(string type)

if (this.d**showprocess.currentrow == null)

messagebox.show("請選擇要需要操作的工序所在行");

else if(type=="del")//刪

if (messagebox.show("確定要刪除嗎?", "警告", messageboxbuttons.yesno) == dialogresult.yes)

this.d**showprocess.rows.remove(this.d**showprocess.currentrow);

else if(type=="up")//上

if (this.d**showprocess.currentrow.index <= 0)

messagebox.show("此工序已在頂端,不能再上移!");

else

int nowindex = this.d**showprocess.currentrow.index;

object _rowdata = (this.d**showprocess.datasource as datatable).rows[nowindex].itemarray;

(this.d**showprocess.datasource as datatable).rows[nowindex].itemarray = (this.d**showprocess.datasource as datatable).rows[nowindex - 1].itemarray;

(this.d**showprocess.datasource as datatable).rows[nowindex-1].itemarray = _rowdata;                  

this.d**showprocess.currentcell = this.d**showprocess.rows[nowindex - 1].cells[0];//設定當前行

else if (type == "down")//下

if (this.d**showprocess.currentrow.index >= this.d**showprocess.rows.count-1)

messagebox.show("此工序已在底端,不能再下移!");

else

int nowindex = this.d**showprocess.currentrow.index;

object _rowdata = (this.d**showprocess.datasource as datatable).rows[nowindex].itemarray;

(this.d**showprocess.datasource as datatable).rows[nowindex].itemarray = (this.d**showprocess.datasource as datatable).rows[nowindex + 1].itemarray;

(this.d**showprocess.datasource as datatable).rows[nowindex+1].itemarray = _rowdata;

this.d**showprocess.currentcell = this.d**showprocess.rows[nowindex + 1].cells[0];//設定當前行

datagridview 整行上移下移

設計器中只是新增了按鈕和datagridview,把datagridview的selectionmode設定為fullrowselect private datatable dt 定義乙個datatable,作為datagridview的資料來源 給datatable賦初值 private void...

C dataGridView上下移動選中行

datagridview 實現行 row 的上下移動,我這裡用到了selectedrows 0 而沒用currentrow是有原因的 主要是這兩段 datagridview1.rows rowindex 1 selected true datagridview1.rows rowindex sele...

java 上下移動資料排序

向上移動就把上一條資料和本條資料的排序字段交換下 update sys custom group as a,sys custom group as b set a.seq b.seq,b.seq a.seq where a.id 051d11d139794532963beb75f40c0afc an...