getting datagrid cell positions and size

J

jamie

I'm looking for a way to be able to edit data in the datagrid similar to how
it works in the full framework. My current thought is when I select a cell
in a datagrid place a textbox in the exact location and focus on the text
box, when done save the value in the datagrid and move the textbox.

Is there a way to get the location and size of the current sell on the
screen?

I'm thinking that on the currentcellchanged event find the currentcell
position on screen.
Set the textbox exactly to that size and position.
Then change the focus to the textbox.

Anyone see any issues with this?

Anyone have a better recommendation?

Jamie
 
J

jamie

This works thank you. Could you explain where the -26 comes from? I
found that I needed to set it to -32 on mine and I believe thats due to the
size of the box due to font size. What exactly is it doing?
Sergey Bogdanov said:
Try this code:

Rectangle r = dataGrid1.GetCellBounds(dataGrid1.CurrentCell.RowNumber,
dataGrid1.CurrentCell.ColumnNumber);
r = dataGrid1.RectangleToScreen(r);

textBox.Top = r.Top - 26;
textBox.Left = r.Left;
textBox.Width = r.Width;
textBox.Height = r.Height;


Probably you will need VScroll/HScroll events of the grid:
http://groups.google.com/group/micr...299d08b30d3/50b62940f767437b#50b62940f767437b


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I'm looking for a way to be able to edit data in the datagrid similar to
how
it works in the full framework. My current thought is when I select a
cell
in a datagrid place a textbox in the exact location and focus on the text
box, when done save the value in the datagrid and move the textbox.

Is there a way to get the location and size of the current sell on the
screen?

I'm thinking that on the currentcellchanged event find the currentcell
position on screen.
Set the textbox exactly to that size and position.
Then change the focus to the textbox.

Anyone see any issues with this?

Anyone have a better recommendation?

Jamie
 
S

Sergey Bogdanov

I was using this value to correct the top position of a cell. The value
26 is a height of a grid header. I'm sure it can be calculated using
private values of a DataGrid control but since a font is predifined you
can leave your "32" value as is.

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

This works thank you. Could you explain where the -26 comes from? I
found that I needed to set it to -32 on mine and I believe thats due to the
size of the box due to font size. What exactly is it doing?
Try this code:

Rectangle r = dataGrid1.GetCellBounds(dataGrid1.CurrentCell.RowNumber,
dataGrid1.CurrentCell.ColumnNumber);
r = dataGrid1.RectangleToScreen(r);

textBox.Top = r.Top - 26;
textBox.Left = r.Left;
textBox.Width = r.Width;
textBox.Height = r.Height;


Probably you will need VScroll/HScroll events of the grid:
http://groups.google.com/group/micr...299d08b30d3/50b62940f767437b#50b62940f767437b


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I'm looking for a way to be able to edit data in the datagrid similar to
how
it works in the full framework. My current thought is when I select a
cell
in a datagrid place a textbox in the exact location and focus on the text
box, when done save the value in the datagrid and move the textbox.

Is there a way to get the location and size of the current sell on the
screen?

I'm thinking that on the currentcellchanged event find the currentcell
position on screen.
Set the textbox exactly to that size and position.
Then change the focus to the textbox.

Anyone see any issues with this?

Anyone have a better recommendation?

Jamie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top