Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expose Grid in UserControl so it can be updated from DS?

Status
Not open for further replies.

Amesville

Programmer
Oct 10, 2011
93
0
0
US
Hi Folks

OK so a few weeks ago I asked about showing several grids on a form, and you folks gave me a great solution (Place them in a panel) which worked great - thank you. As it turns out there were more controls than just the grids to display repetitively (labels, text boxes, bottons) that went with each grid, so I floated the idea of creating a UserControl with a grid and the other necessary objects for each system that requires reporting on, that way they could have a solution that would be flexible for other clients as well, and not be limited to just four grids, plus they could close or open any system they wanted to see or not see. Well, they loved that!

So I'm in the process of building out the 'generic' UserControl, and I'm wondering if can I expose the grid datasource on the UserControl as Public and assign it to a dataset / table in the main form? Will that work? If it matters at all these are TrueDBGrid controls and not the standard MS grid control.

Also I found that the current way the application works is that there is a 'dummy' grid control placeholder on the form that is swapped out at runtime by a customized grid control. The customized control is defined as a class in the application. Would it be possible for me to assign the customized grid into the UserControl at runtime from the parent form, and how can I expose that functionality to allow it to happen?

Thanks for any help you can offer. I'm trying to answer this myself via the web but so far I'm not finding an explanation that addresses what I'm looking for specifically.
 

You should be able to do all of that.

First, to set the DataSource you could create a property in your UC to expose the grid, like so:

Public Property TheGrid() As TrueDBGrid
Get
Return tgGrid 'use the name of the grid control here
End Get
Set(ByVal Value As TrueDBGrid)
tgGrid = Value 'use the name of the grid control here
End Set
End Property

Then when the UC is instantiated, you can do this:

UserControl1.TheGrid.DataSource = <data source>

And, you can assign your customized grid like so:

UserControl1.TheGrid = <the customized grid>


I'm not 100% sure about that last one since you said it is "defined as a class". But this should get you going on the right path.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top