Click here to Skip to main content
15,349,648 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
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

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...

1 solution

Dear Krishna,

You can get selected row and column index by using e.ColumnIndex,e.RowIndex on dataGridView1_CellContentClick event.
krishna kishore58 30-Nov-10 23:08pm
sorry i know this, but i wanna know the selected cell location so that i can place the textbox over there... so that even though i scroll down the gridview the location issue doesnot arise... if u can pls help me out...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900