C# dataGridView 单元格 坐标

来源:百度知道 编辑:UC知道 时间:2024/06/01 18:58:15
C# dataGridView 单元格 坐标
窗体上有:
dataGridView1控件.(数据图表)
一个button1控件.(按钮)
要求点一下dataGridView1里面的任何一个单元格,button1就移到该单元格的上面.
说到底就是得到被选中单元格的坐标值,然后button1.top= 与button2.left= 来设置按钮的坐标.

用js处理
加入js方法wahaha(),并且在body的onload中引用,下面是代码: 按钮样式设定下

<head runat="server">
<title>无标题页</title>
<script>
function wahaha()
{
var tbl = document.getElementById('GridView1');
var btn = document.getElementById('Button1');
for(var i=1; i<tbl.rows.length; i++)
{
for(var j=0; j<tbl.rows[i].cells.length; j++)
{
tbl.rows[i].cells[j].onclick=function()
{
//alert(this.offsetLeft + " : " + this.offsetTop);
btn.style.left = this.offsetLeft+10;
btn.style.top = this.offsetTop+16;
btn.style.width = this.offsetWidth;
btn.style.height = this.offsetHeight;
}
}
}
}
</script>
</head>
<body onload="wahaha();">
....
<asp:Button ID="Button1" runat="server" Text="Button" style="position:absolute;width:100px;