user control with a datagrid control in it

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I have a user control with a datagrid in it.

Here is what I would like to do

* As the width of the datagrid grows or shrinks, have the user control
adjust so that it always looks full in the user control with no
scrolls. The datagrid's columns can be hidden or shown at run time,
so I cannot predict what the width will be until runtime.

* Also have that user control always centered.

In other words, I am trying to emulate how user controls behave on the
Web. Thank you.
 
First the first one, you would need to set the Usercontrol properties in the
usercotnrol designer to autosize=true, and AutoSizeMode = GrowAndShrink.
Then handle the columns added, columns removed, columnresized events on the
datagridview and set the size of the grid to the PrefferedSize property. That
is the size it would be to have no scroll bars.

For always centred. Centre it in the designer (theres a toolbar item for
that), then change the Anchor to be top (no left or right) and it will stay
in the centre,

HTH
 
Back
Top