选择datagridview 单元格时如何获取单元的坐标?(就是 x,y 的值 我要代码详细的啊)

dreamchenliang88 2009-05-15 10:49:39
选择datagridview 单元格时如何获取单元的坐标?(就是 x,y 的值 我要代码详细的啊)急急!
(有实例更好)
...全文
787 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgke 2009-05-15
  • 打赏
  • 举报
回复
Rectangle _CellRectangle = dataGridView1.GetCellDisplayRectangle(0, 0, true);
北京的雾霾天 2009-05-15
  • 打赏
  • 举报
回复
使用如下方法:

DataGridView.GetCellDisplayRectangle 方法

public Rectangle GetCellDisplayRectangle (
int columnIndex,
int rowIndex,
bool cutOverflow
)
  • 打赏
  • 举报
回复

int num1=this.dataGridView1.CurrentCell.ColumnIndex;//獲取當前單元格列的索引值
int num2 = this.dataGridView1.CurrentCell.RowIndex;//獲取當前單元格行的索引值

你自己组合吧,哈哈……
dreamchenliang88 2009-05-15
  • 打赏
  • 举报
回复
我实例就更好了 我急需啊 快点
surlew 2009-05-15
  • 打赏
  • 举报
回复

private void DataGridview1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
string value = "";
if (e.RowIndex > -1 && e.ColumnIndex > -1)
{
//取得当前单元格的值
value = grd.grd.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
//获取单元格的坐标
int i = MousePosition.X;
int j = MousePosition.Y;
}
}

dreamchenliang88 2009-05-15
  • 打赏
  • 举报
回复
我在datagridview1中附加了datagridview2 就是想让 datagridview1 添加一行时, datagridview2 获取坐标 紧跟这移动。
dreamchenliang88 2009-05-15
  • 打赏
  • 举报
回复
谢谢啊 ,我需要实例 。关于这方面的例子。谢谢了 。快点了 我急急!!!

  • 打赏
  • 举报
回复

string str = this.dataGridView1.CurrentCell.Value.ToString();//獲取選中單元格的值
string strHeaderTest = this.dataGridView1.Columns[1].HeaderCell.Value.ToString();//獲取選中列的表頭
surlew 2009-05-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 surlew 的回复:]
C# code
if (e.RowIndex > -1 && e.ColumnIndex > -1)
{
MousePosition.X
MousePosition.Y
//此时X,Y在单元格范围之内
}
[/Quote]

补充:是在_CellMouseEnter事件里面
surlew 2009-05-15
  • 打赏
  • 举报
回复

if (e.RowIndex > -1 && e.ColumnIndex > -1)
{
MousePosition.X
MousePosition.Y
//此时X,Y在单元格范围之内
}
  • 打赏
  • 举报
回复

private void getCurrentCellButton_Click(object sender, System.EventArgs e)
{
string msg = String.Format("Row: {0}, Column: {1}",
dataGridView1.CurrentCell.RowIndex,
dataGridView1.CurrentCell.ColumnIndex);
MessageBox.Show(msg, "Current Cell");
}


这是msdn里面的代码,待会我传我自己的吧,我都在搞这个东西呢

111,101

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧