RT通过坐标点来定位dataGridView 的某一行,谢谢
解决方案 »
- .Net如何定时激发时间?
- Hashtable和SortedList和Dictionary他们的功能一样???
- 谁用过Epson MT532的热敏打印机,有没有相关的驱动和SDK啊?
- ???如何替换网页中不在tag < > 和 ( )之间的字符串?
- 各位大侠们帮忙找一下错误,是一个连续IP地址端口扫描程序
- 求 按实际图的比例 绘制展位图的原理及C#程序实现方法
- vs.Net 2003 安装不能自定义安装路径。请问怎么解决
- C#操作如何修改、添加Excel中的单元格的数据????求高手指点呀。。。在线等待。。。。
- 初学者的问题,高分请教
- 设计器加载失败,说是发生了未经处理的错误
- 谁能告诉我这是什么架构
- 后台除了Session控制权限外,还有其他的吗?
是Winform谢谢
public int GetRowIndexAt(int mouseLocation_Y)
{
if (dataGridView1.FirstDisplayedScrollingRowIndex < 0)
{
return -1; // no rows.
}
if (dataGridView1.ColumnHeadersVisible == true && mouseLocation_Y <= dataGridView1.ColumnHeadersHeight)
{
return -1;
}
int index = dataGridView1.FirstDisplayedScrollingRowIndex;
int displayedCount = dataGridView1.DisplayedRowCount(true);
for (int k = 1; k <= displayedCount; ) // 因为行不能ReOrder,故只需要搜索显示的行
{
if (dataGridView1.Rows[index].Visible == true)
{
Rectangle rect = dataGridView1.GetRowDisplayRectangle(index, true); // 取该区域的显示部分区域
if (rect.Top <= mouseLocation_Y && mouseLocation_Y < rect.Bottom)
{
return index;
}
k++; // 只计数显示的行;
}
index++;
}
return -1;
} 测试用代码: 把当前行的index号(从0开始)显示到TextBox1上。
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text= GetRowIndexAt(e.Y).ToString();
}