选择datagridview 单元格时如何获取单元的坐标?(就是 x,y 的值 我要代码详细的啊) 选择datagridview 单元格时如何获取单元的坐标?(就是 x,y 的值 我要代码详细的啊)急急!(有实例更好) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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里面的代码,待会我传我自己的吧,我都在搞这个东西呢 if (e.RowIndex > -1 && e.ColumnIndex > -1){ MousePosition.X MousePosition.Y //此时X,Y在单元格范围之内} 补充:是在_CellMouseEnter事件里面 string str = this.dataGridView1.CurrentCell.Value.ToString();//獲取選中單元格的值string strHeaderTest = this.dataGridView1.Columns[1].HeaderCell.Value.ToString();//獲取選中列的表頭 我在datagridview1中附加了datagridview2 就是想让 datagridview1 添加一行时, datagridview2 获取坐标 紧跟这移动。 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; } } int num1=this.dataGridView1.CurrentCell.ColumnIndex;//獲取當前單元格列的索引值int num2 = this.dataGridView1.CurrentCell.RowIndex;//獲取當前單元格行的索引值你自己组合吧,哈哈…… 使用如下方法:DataGridView.GetCellDisplayRectangle 方法public Rectangle GetCellDisplayRectangle ( int columnIndex, int rowIndex, bool cutOverflow) Rectangle _CellRectangle = dataGridView1.GetCellDisplayRectangle(0, 0, true); 遗传算法 用C#怎么实现操作EXCEL表 紧急求助,数据库问题 赚点分,发个赚分贴 c#安装部署 怎么在datagrid中判断里面的数值,当它为负时,数值变为红色? QUERY.DLL的LoadIFlter()函数 急求解答 Json字符串解析 怎么用C#的webBrowser模拟点击天猫页面上的标签 简单小问:C#中如何判断一对象为空? 2.急求需要能运行出来的完整程序!急啊! WPF 里面怎么让时间轴循环运行啊?只有beginstorybord什么的,想不到好的办法。
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里面的代码,待会我传我自己的吧,我都在搞这个东西呢
if (e.RowIndex > -1 && e.ColumnIndex > -1)
{
MousePosition.X
MousePosition.Y
//此时X,Y在单元格范围之内
}
补充:是在_CellMouseEnter事件里面
string str = this.dataGridView1.CurrentCell.Value.ToString();//獲取選中單元格的值
string strHeaderTest = this.dataGridView1.Columns[1].HeaderCell.Value.ToString();//獲取選中列的表頭
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;
}
}
int num1=this.dataGridView1.CurrentCell.ColumnIndex;//獲取當前單元格列的索引值
int num2 = this.dataGridView1.CurrentCell.RowIndex;//獲取當前單元格行的索引值你自己组合吧,哈哈……
int columnIndex,
int rowIndex,
bool cutOverflow
)