日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

DataGridView删除、修改方法封装

發布時間:2025/7/14 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DataGridView删除、修改方法封装 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
private int curRow = 0;//鼠標右鍵得到的當前行號 #region 激發鼠標事件,顯示右鍵菜單,得到被選中的行的行號,注意第一列被隱藏的情況考慮
??????? private?int showRightMenu(DataGridView dataGridView, ContextMenuStrip contextMenuStrip, DataGridViewCellMouseEventArgs e)
??????? {
??????????? int curRowTemp = 0;//當前鼠標在DataGridView中的行的位置
??????????? if (e.Button == MouseButtons.Right)
??????????? { curRowTemp = e.RowIndex; if (curRowTemp < 0 || curRowTemp > dataGridView.Rows.Count)
??????????????? {
??????????????????? curRowTemp = 0;
??????????????? }
??????????????? else
??????????????? {
??????????????????? dataGridView.CurrentCell = dataGridView[1, curRowTemp];
??????????????????? dataGridView.ContextMenuStrip = contextMenuStrip; }
??????????? }
??????????? return curRowTemp;//返回當前鼠標所在的行的行號
??????? }
??????? #endregion #region 根據行號,得到DataGridView中該行的某一列的信息
??????? private Object GetColumeInfo(DataGridView dataGridView, int curRow, int colnum)
??????? {
??????????? Object info = null;
??????????? info = dataGridView.Rows[curRow].Cells[colnum].Value;
??????????? return info;
??????? }
??????? #endregion #region 根據行號,設置DataGridView中該行的某一列的信息
??????? private int SetColumeInfo(DataGridView dataGridView, int curRow, int column, Object info)
??????? {
??????????? dataGridView.Rows[curRow].Cells[column].Value = info;
??????????? return (int)this.GetColumeInfo(dataGridView, curRow, 0);
??????? }
??????? #endregion #region 根據行號,刪除該行
??????? private int RemoveRow(DataGridView dataGridView, int curRow)
??????? {
??????????? int rowID = (int)this.GetColumeInfo(dataGridView, curRow, 0);
??????????? dataGridView.Rows.RemoveAt(curRow); System.Console.WriteLine("刪除的索引號" + rowID + "刪除的行號" + curRow);
??????????? return rowID; }
??????? #endregion

轉載于:https://www.cnblogs.com/hzuIT/articles/688919.html

總結

以上是生活随笔為你收集整理的DataGridView删除、修改方法封装的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。