How to get _true_ client area of datagrid

  • Thread starter Thread starter Julie
  • Start date Start date
J

Julie

I need to get the actual client area of the datagrid.

DataGrid.ClientSize doesn't seem to take into account: borders and scrollbars
(if visible).

What I need is a way to get the visible width, excluding borders and
scrollbars.

Any clues?
 
The only thing I can suggest is to take a screen capture (from some graphics package) of the datagrid scrollbar and measure it, as the scrollbar is always the same size, then add a pixel or two for the border and set up the rectangle like that

eg.

Rectangle rect = new Rectangle(this.dataGrid.ClientRectangle.X-1, this.dataGrid.ClientRectange.Y-1, this.datagrid.ClientRectangle.Width + widthOfScrollbar + 2, this.dataGrid.ClientRectangle.Height + scrollbar + 2)

the + 2 is to make up for the pixel lost when you set the location more to the left above and you'll have to add another to get the border on the other side. If the scrollbar is sometimes visible and sometimes not, you might want to run some code to find out how many rows are in the grid and if that exceeds the maximum visible and will therefore result in the scrollbars being visible

It's not a great solution but it'll work
Hope that helps in some way

jax
 

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

Back
Top