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

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - ☆用心生活☆

BI-日期维度表-SQL SERVER SQL SERVER 2014 缺少Business Intelligence 解决办法 有未提交的事务。是否要在关闭窗口之前提交这些事务? 获取对象属性和值 日志记录 MSSQL之2005版本之后的行号分区妙用:row_number() over(PARTITION BY X1,X2.. ORDER BY X1,X2... ) IIS发布服务时候无法浏览,提示需要MIME注册 深浅COPY之我所理解,望拍砖交流。 windows developer preview 安装体验。 MSSQL之自增列丢失ID找回--粗略解决方案 datagirdview进行数据统计 水晶报表之分页预留空白方便打印信纸 SQLMETAL使用LINQ自动代码生成工具命令残参数详解 aspnet_compiler.exe 命令参数详解 妙用MSSQL的REVERSE()反转函数显示文件路径的文件名称 2011年上半年总结 windows phone 7 学习初旅1 MSSQL自定义函数之数据格式化为千分位格式 MSSQL获取指定表的列名信息,描述,数据类型,长度 The product level is insufficient for component "Data Conversion 1"
DataGridView数据呈现之行信息--HitTestInfo--用于选择呈现第一行
☆用心生活☆ · 2011-08-06 · via 博客园 - ☆用心生活☆

公告QQ群:124766907,若你是在.NET领域有独到见解,并有深厚的编程功力,在某一领域具有专长,欢迎本您入群,本群已经有好几位MVP,在SL,.NET,BS方面具有造诣的人欢迎进群。无4年以上经验者勿加,本群追寻高端顶级,多谢。

由于子窗体进行了数据更改,保存,需要刷新父窗体BODY里DataGridView里的数据,因此,当BODY里的数据量比较大,而你刚好是选的是当前行比较靠后,又要刷新父窗体的时候,可能默认就数据定位到第一行了。也许你以前是用的是dataGridView.CurrentRow.Index进行记录,然后FirstDisplayedScrollingRowIndex里进行值更改,让后再使用FirstDisplayedScrollingRowIndex进行行确定行的位置,然后可能使用到FirstDisplayCell属性进行当前光标的定位。

现在可以直接使用DATAGRIDVIEW的HitTestInfo方法,获取当前鼠标定位到的行列索引,HitTestInfo自己就包含了行列索引,或者包含了当前鼠标在屏幕中的X,Y坐标,可以根据这些属性进行再定位。

 /// <summary>
/// 鼠标点击的时候就获取当前的HitTestInfo信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
// hittest全局变量DataGridView.HitTestInfo hittest;
hittest = dataGridView1.HitTest(e.X, e.Y);
//MessageBox.Show(hittest.ToString());
this.dataGridView1.Rows[hittest.RowIndex].Selected = true;
}
//测试重新定位。
private void button1_Click(object sender, EventArgs e)
{
if (hittest != null)
{
dataGridView1.FirstDisplayedScrollingRowIndex
= hittest.RowIndex;
}
else
{
dataGridView1.FirstDisplayedScrollingRowIndex
= 0;
}
}

也可以直接定义全局变量,获取行索引,然后定位到第一个单元格就OK了

dgvDetails.CurrentCell = 
dgvDetails.Rows[currentBodyDetailRowIndexSelected].Cells[0];//再重新定位到当前行
dgvDetails.FirstDisplayedScrollingRowIndex
 = currentBodyDetailRowIndexSelected;
dgvDetails.FirstDisplayedCell =
 dgvDetails.Rows[currentBodyDetailRowIndexSelected].Cells[0];