DataGridView单元格 [英] DataGridView Cell
本文介绍了DataGridView单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我需要知道所选的单元格位置,以便可以在其上放置文本框.
我可以使用以下代码在选定的单元格上放置文本框
Hello, I need to know the selected cell location so that i can place the textbox on it.
Iam able to place the textbox on the selected cell with following code
for(r=0;r<=row-2;r++)
{
txtValueChange.Left = dataGridView1.Left + dataGridView1.ColumnHeadersHeight + 8 + dataGridView1.Columns[0].Width;
if (!dataGridView1.CurrentRow.IsNewRow)
{
for (int j = 1; j<= 7; j++)
{
if (dataGridView1.Rows[r].Cells[j].Selected == true)
{
txtValueChange.Width = dataGridView1.Columns[j].Width;
txtValueChange.Left += dataGridView1.Columns[j].Width;
}
}
txtValueChange.Top += dataGridView1.RowTemplate.Height;
lbRateID.Top += dataGridView1.RowTemplate.Height;
}
但是问题是当我滚动水平滚动器时,很少的列会隐藏,并且文本框的左侧位置会自动不同.因为
But the issue is when i scroll the horizontal scroller, few columns get hide and the textbox left location automatically differs. Because
txtValueChange.Left += dataGridView1.Columns[j].Width;
如果我知道所选单元格的位置,就可以解决此问题.或者,如果有其他替代解决方案,请让我知道...
I can able to solve this issue if i come to know the selected cells location. Or if there exists any alternate solution pls let me know...
推荐答案
亲爱的克里希纳,
您可以通过使用dataGridView1_CellContentClick事件上的e.ColumnIndex,e.RowIndex获得选定的行和列索引.
Dear Krishna,
You can get selected row and column index by using e.ColumnIndex,e.RowIndex on dataGridView1_CellContentClick event.
这篇关于DataGridView单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文