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

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - ☆用心生活☆

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];