当前位置:网站首页>DataGridView上移 下移行
DataGridView上移 下移行
2022-06-30 00:23:00 【Izrj】
/// <summary>
/// 下移
/// </summary>
/// <param name="dataGridView"></param>
public void MoveToDownRow(DataGridView dataGridView)
{
try
{
var index = dataGridView.CurrentCell.RowIndex;
if (dataGridView.RowCount > 0)
{
if (index >= 0 & (dataGridView.RowCount - 1) != index)//如果该行不是最后一行
{
DataGridViewRow dgvr = dataGridView.Rows[index];//获取选中行的下一行
dataGridView.Rows.RemoveAt(index);//删除原选中行
dataGridView.Rows.Insert((index + 1), dgvr);//将选中行的上一行插入到选中行的后面
dataGridView.Rows[index].Selected = false;
for (int i = 0; i < dataGridView.Rows[index].Cells.Count; i++)
{
dataGridView.Rows[index].Cells[i].Selected = false;
}
index = index + 1 > dataGridView.RowCount - 1 ? 0 : index + 1;
dataGridView.Rows[index].Selected = true;//选中这行
dataGridView.CurrentCell = dataGridView.Rows[index].Cells[0];//重新设置活动单元格
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
/// <summary>
/// 上移
/// </summary>
/// <param name="dataGridView"></param>
public void MoveToUpRow(DataGridView dataGridView)
{
try
{
var index = dataGridView.CurrentCell.RowIndex;//获取当前活动行的索引
var row = dataGridView.Rows[index];
if (row != null)
{
if (index > 0)//如果该行不是第一行
{
DataGridViewRow dgvr = dataGridView.Rows[index - 1];//获取选中行的上一行
dataGridView.Rows.RemoveAt(index - 1);//删除原选中行的上一行
dataGridView.Rows.Insert((index), dgvr);//将选中行的上一行插入到选中行的后面
for (int i = 0; i < dataGridView.RowCount; i++)//选中被操作的行
{
if (i > index)
{
index = index - i - 1 < 0 ? 0 : index - i - 1;
dataGridView.Rows[index].Selected = true;
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
边栏推荐
- MySQL基础篇1
- C MDI open subform to remove automatically generated menu bar
- Solr基础操作9
- Solr basic operation 6
- 云呐|如何利用系统管理固定资产?如何进行固定资产管理?
- JS draw polar color gradient
- Sword finger offer II 035 Minimum time difference
- Fine grained identification, classification, retrieval data set collation
- label问题排查:打不开标注好的图像
- MySQL基础2
猜你喜欢
![[dynamic programming] - linear DP](/img/cb/4ad8dce1da1d1110d6e79fadca4293.png)
[dynamic programming] - linear DP
![[QNX Hypervisor 2.2用户手册]6.2.2 Guest与Host之间通信](/img/a4/a84f916d3aa2cc59f5b686cd32797a.png)
[QNX Hypervisor 2.2用户手册]6.2.2 Guest与Host之间通信

8 software engineering environment

QT learning 03 birth and essence of QT

SSH key disclosure (module B competition topic) -- Application Service Vulnerability scanning and utilization

分布式任务调度 ElasticJob demo

基于zfoo开发项目的一些规范

EB-5 immigration in the United States reappears to be positive, and the reauthorization policy of the regional center is suspended
![克隆无向图[bfs访问每条边而不止节点]](/img/34/2a1b737b6095293f868ec6aec0ceeb.png)
克隆无向图[bfs访问每条边而不止节点]

Statistical query of SQL Server database
随机推荐
About SQL: create a view_ XB view, whose function is ① to delete views with duplicate names before creating them ② to display the number of male and female students in this class in the XSB table, and
Sword finger offer II 037 Asteroid collision
[advanced C language] dynamic memory management
Solr基础操作8
TP5 query and and or condition nesting
Solr基础操作12
Statistical query of SQL Server database
Solr基础操作15
VIM plug in manager VIM plug installation method
Solr基础操作13
Solr基础操作9
Color space conversion in video tonemapping (HDR to SDR) (bt2020 to bt709, YCbCr, YUV and RGB)
QT learning 03 birth and essence of QT
Three postures of anti CSRF blasting
Applying for let's encrypt SSL certificate with certbot
Stack space of JVM
【UITableView】坑一:tableView:heightForHeaderInSection:方法不执行
How to realize the spelling correction function in search engine
Store log files in RAM to reduce physical storage loss
QT learning 05 introduction to QT creator project