惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
D
Docker
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
F
Full Disclosure
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
L
LangChain Blog
H
Help Net Security
B
Blog
T
Tailwind CSS Blog
V
V2EX
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
美团技术团队
A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
I
InfoQ
Project Zero
Project Zero
I
Intezer
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
S
Securelist
Recorded Future
Recorded Future
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - 叶小钗
S
Security Affairs
Blog — PlanetScale
Blog — PlanetScale
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
The Hacker News
The Hacker News

博客园 - CsharpFish

Sql2005 PIVOT运算符的操作 Lodop使用之WEB套打程序开发 jquery插件treeTable Asp.net 后台添加CSS、JS、Meta标签的写法 CodeSmith----SchemaExplorer类结构详细介绍 - CsharpFish - 博客园 js request 应用举例 背景图片随窗口拉伸 WebBrowser网页局部打印 - CsharpFish - 博客园 js日期控件-梅花雨 利用VML生成柱状图和饼图 js操作Table绑定DataSet 小小个人消费管理系统(已完善) GridView分页用户自定义控件 DbType与OleDbType 添加修改后返回刷新查询页面 asp.net页面传值(transfer Context.Handler) GridViev皮肤(Skin&CSS) JavaScript验证控件并阻止表单提交 GridView自定义分页存储过程
DataGridView拖动换行
CsharpFish · 2011-06-16 · via 博客园 - CsharpFish

1. 功能

  鼠标点击行首拖动换行

  多行选择删除

2. 主要代码

View Code

        private void dgv_SelectionChanged(object sender, EventArgs e)
        {
            
if (dgv.Rows.Count > 0 && selectionIdx > -1 && selectionIdx < dgv.Rows.Count - 1)// (dgv.SelectedRows.Count > 0))
            {if (dgv.Rows.Count <= selectionIdx)
                    selectionIdx 
= dgv.Rows.Count - 1;
                dgv.Rows[selectionIdx].Selected 
= true;
                
//dgv.CurrentCell = dgv.Rows[selectionIdx].Cells[0];
            }
        }
private void dgv_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            
if (e.RowIndex >= 0)
                selectionIdx 
= e.RowIndex;
        }
private void dgv_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
        {
            
if ((e.Clicks < 2&& (e.Button == MouseButtons.Left))
            {
                
if ((e.ColumnIndex == -1&& (e.RowIndex > -1))
                    dgv.DoDragDrop(dgv.Rows[e.RowIndex], DragDropEffects.Move);
            }
        }
private void dgv_DragDrop(object sender, DragEventArgs e)
        {
            
int idx = GetRowFromPoint(e.X, e.Y);
            
if (idx < 0return;if (e.Data.GetDataPresent(typeof(DataGridViewRow)))
            {
                DataGridViewRow row 
= (DataGridViewRow)e.Data.GetData(typeof(DataGridViewRow));
                DataRow ddr 
= ((DataRowView)row.DataBoundItem).Row;
                DataRow nr 
= ((DataTable)dgv.DataSource).NewRow();for (int i = 0; i < row.Cells.Count; i++)
                {
                    nr[i] 
= row.Cells[i].Value;
                }
                selectionIdx 
= idx;
                ((DataTable)dgv.DataSource).Rows.InsertAt(nr, idx);
                ((DataTable)dgv.DataSource).Rows.Remove(ddr);
                dgv.ClearSelection();
            }
        }
private void dgv_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect 
= DragDropEffects.Move;
        }
private int GetRowFromPoint(int x, int y)
        {
            
for (int i = 0; i < dgv.RowCount; i++)
            {
                Rectangle rec 
= dgv.GetRowDisplayRectangle(i, false);if (dgv.RectangleToScreen(rec).Contains(x, y))
                    
return i;
            }
return -1;
        }

  源码下载