Form as a control?

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,

Is there a way to have a form as a control? Here's what I want to do:

I have a datagrid which displays various information. However, I want to
use it in multiple locations within the same application. Instead of
creating an instance of the grid and linking up the same data on each form,
I want to have a "floating" form which contains my grid in my application.
When a new form needs this grid, I would, say, take the form (with the grid)
and add it to a panel as a child control ... does this work?

Is this even a good approach? Any examples?

Thanks in advance,

Chris
 
Chris said:
Hi,

Is there a way to have a form as a control? Here's what I want to do:

I have a datagrid which displays various information. However, I want to
use it in multiple locations within the same application. Instead of
creating an instance of the grid and linking up the same data on each form,
I want to have a "floating" form which contains my grid in my application.
When a new form needs this grid, I would, say, take the form (with the grid)
and add it to a panel as a child control ... does this work?

Is this even a good approach? Any examples?

Thanks in advance,

Chris

Instead of a form as a base for you grid, use a panel.
So you can create a control panel+grid on it. This way you can create PanelGrid control one time and
then place it on different forms/panels

Hope it helps,
Andrey aka MuZZy
 
I have a datagrid which displays various information. However, I want to
use it in multiple locations within the same application. Instead of
creating an instance of the grid and linking up the same data on each form,
I want to have a "floating" form which contains my grid in my application.
When a new form needs this grid, I would, say, take the form (with the grid)
and add it to a panel as a child control ... does this work?

Is this even a good approach? Any examples?

A form is a nothing more than a control (it derives from ContainerControl).
So you can use a form as you would use any other control and place it
within other container controls (such as Panels) if you wish. However, in
your case, i would suggest you to simply create a User Control (right click
on your project, add new item -> user control). Place your datagrid on this
control, add all the public methods you need and there you go. You can then
place this control wherever you want, move it from one place to another...
 
Chris said:
Is there a way to have a form as a control? Here's what I want to do:

I have a datagrid which displays various information. However, I want
to use it in multiple locations within the same application. Instead of
creating an instance of the grid and linking up the same data on each
form, I want to have a "floating" form which contains my grid in my
application. When a new form needs this grid, I would, say, take the
form (with the grid) and add it to a panel as a child control ... does
this work?

Make a panel with a grid, then make it a user control and you can then redrop
it on any form to reuse it.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
 
Back
Top