Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Help with Panel and User Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Cosmas - 08 Apr 2005 21:04 GMT
I have a parent form that has a combobox.  In the parent, I placed a
UserControl (created as NEW) inside a Panel that contains a grid that
returns data.  As I change the selection of the combobox on the parent, I
would like to see the data in the UserControl embedded in the panel updated
as well.  I'm having to acutally use the .Clear method and .Add(UserControl)
to force the control to reload in the Panel whenever the
Combobox.SelectedItem_Changed occurs.  I would like to use a method like a
REFETCH, of figure out a way to tell the underlying UserControl object
living in the panel to update whenever the parent record/combobox changes.
Please help.

John
Ken Tucker [MVP] - 09 Apr 2005 11:45 GMT
Hi,

           Maybe you can use databinding
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/v
bnet02122002.asp


Ken
--------------------
I have a parent form that has a combobox.  In the parent, I placed a
UserControl (created as NEW) inside a Panel that contains a grid that
returns data.  As I change the selection of the combobox on the parent, I
would like to see the data in the UserControl embedded in the panel updated
as well.  I'm having to acutally use the .Clear method and .Add(UserControl)
to force the control to reload in the Panel whenever the
Combobox.SelectedItem_Changed occurs.  I would like to use a method like a
REFETCH, of figure out a way to tell the underlying UserControl object
living in the panel to update whenever the parent record/combobox changes.
Please help.

John
John Cosmas - 09 Apr 2005 17:25 GMT
Databinding is not the issue here.  I think we're confusing the matter.  I
need to instruct the object (child), which is the usercontrol that I've
loaded into the panel in the parent form to refresh its data, or move to the
next record, by virtue of a filter.  So what code would I use to tell the
usercontrol to do something.  Let's look at the details...

This is the code that loads the user control that sits on the parent form:

Private Sub ps_Setup_TrialWorks_Expenses_Desktop()

   With Me.ddlMainLookup
       .DataSource = gdsTrialWorks.Tables("twCaseTableLookup")
       .ValueMember = "CaseId"
       .DisplayMember = "CaseName"
       .Enabled = True
       .Refresh()
   End With

   glngtwCaseID = 0
   Dim puscTWExpenses As New uscTWExpenses
   Me.panDesktop.Controls.Add(puscTWExpenses)

End Sub

So when I change/select another record on the parent, here is what I'm
having to do to make it work currently, which is slow and sloppy

Private Sub ddlMainLookup_SelectedValueChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ddlMainLookup.SelectedValueChanged
       Me.panDesktop.Controls.Clear()

       glngtwCaseID = .SelectedValue
       Dim puscTWExpenses As New uscTWExpenses
       Me.panDesktop.Controls.Add(puscTWExpenses)

End Sub

As you can see, I'm having to clear the panel and reload it, which happens
to yeild the results I need.  But this is rather slow and clumsy.  I need to
be able to invoke a method that tell puscTWExpenses to refresh/requery it's
data so it will show me the returns for matching header data in the parent
form which lives in panDesktop.

John

> Hi,
>
>             Maybe you can use databinding

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/v
bnet02122002.asp


> Ken
> --------------------
[quoted text clipped - 10 lines]
>
> John
Ken Tucker [MVP] - 09 Apr 2005 17:44 GMT
Hi,

       I dont see where you add data to puscTWExpenses maybe you could post
the code for that.  Really dont see why you have to clear the control and
readd it.

Ken
---------------
Databinding is not the issue here.  I think we're confusing the matter.  I
need to instruct the object (child), which is the usercontrol that I've
loaded into the panel in the parent form to refresh its data, or move to the
next record, by virtue of a filter.  So what code would I use to tell the
usercontrol to do something.  Let's look at the details...

This is the code that loads the user control that sits on the parent form:

Private Sub ps_Setup_TrialWorks_Expenses_Desktop()

   With Me.ddlMainLookup
       .DataSource = gdsTrialWorks.Tables("twCaseTableLookup")
       .ValueMember = "CaseId"
       .DisplayMember = "CaseName"
       .Enabled = True
       .Refresh()
   End With

   glngtwCaseID = 0
   Dim puscTWExpenses As New uscTWExpenses
   Me.panDesktop.Controls.Add(puscTWExpenses)

End Sub

So when I change/select another record on the parent, here is what I'm
having to do to make it work currently, which is slow and sloppy

Private Sub ddlMainLookup_SelectedValueChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ddlMainLookup.SelectedValueChanged
       Me.panDesktop.Controls.Clear()

       glngtwCaseID = .SelectedValue
       Dim puscTWExpenses As New uscTWExpenses
       Me.panDesktop.Controls.Add(puscTWExpenses)

End Sub

As you can see, I'm having to clear the panel and reload it, which happens
to yeild the results I need.  But this is rather slow and clumsy.  I need to
be able to invoke a method that tell puscTWExpenses to refresh/requery it's
data so it will show me the returns for matching header data in the parent
form which lives in panDesktop.

John

> Hi,
>
>             Maybe you can use databinding

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/v
bnet02122002.asp


> Ken
> --------------------
> I have a parent form that has a combobox.  In the parent, I placed a
> UserControl (created as NEW) inside a Panel that contains a grid that
> returns data.  As I change the selection of the combobox on the parent, I
> would like to see the data in the UserControl embedded in the panel
updated
> as well.  I'm having to acutally use the .Clear method and
.Add(UserControl)
> to force the control to reload in the Panel whenever the
> Combobox.SelectedItem_Changed occurs.  I would like to use a method like a
[quoted text clipped - 3 lines]
>
> John
John Cosmas - 09 Apr 2005 21:33 GMT
Ken;

Here is what happens when the user control is loaded
If glngtwCaseID = 0 Then
   .DataSource = Nothing
Else
   .DataSource = gdsTrialWorks.Tables("twExpense").Select("CaseId = " &
glngtwCaseID)
   .Refetch()
End If

I declared glngtwCaseID as public so it can be seen from frmDesktop parent
from and set from it too.  Again, I need some code that I can run from the
parent where I can instruct the loaded usercontrol to refetch the data,
filter it or reselect which eliminates reloading the entire control in the
code I sent previously.  I used to be able to control such things in MS
Access when I declare the object.  My real problem is trying to control the
loaded user control from the parent.  The panel is a placeholder, which is
used to load various user controls and that's why I have to get past this
first problem.

> Hi,
>
[quoted text clipped - 52 lines]
> >
> >             Maybe you can use databinding

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/v
bnet02122002.asp


> > Ken
> > --------------------
[quoted text clipped - 12 lines]
> >
> > John
Ken Tucker [MVP] - 10 Apr 2005 19:52 GMT
Hi,

           Try something like this.  It will loop through the controls
added to the panel and allow you to change the datasource of the user
control.

For each ctrl as control in ddMainLookup.controls

       if typeof ctrl is uscTWExpenses then
          with  DirectCast(ctrl, uscTWExpenses)
               .datasource =
gdsTrialWorks.Tables("twExpense").Select("CaseId = " &
glngtwCaseID)
           .Refetch()
       end if
next

Ken
--------------------
Ken

Here is what happens when the user control is loaded
If glngtwCaseID = 0 Then
   .DataSource = Nothing
Else
   .DataSource = gdsTrialWorks.Tables("twExpense").Select("CaseId = " &
glngtwCaseID)
   .Refetch()
End If

I declared glngtwCaseID as public so it can be seen from frmDesktop parent
from and set from it too.  Again, I need some code that I can run from the
parent where I can instruct the loaded usercontrol to refetch the data,
filter it or reselect which eliminates reloading the entire control in the
code I sent previously.  I used to be able to control such things in MS
Access when I declare the object.  My real problem is trying to control the
loaded user control from the parent.  The panel is a placeholder, which is
used to load various user controls and that's why I have to get past this
first problem.

> Hi,
>
>         I dont see where you add data to puscTWExpenses maybe you could
post
> the code for that.  Really dont see why you have to clear the control and
> readd it.
[quoted text clipped - 4 lines]
> need to instruct the object (child), which is the usercontrol that I've
> loaded into the panel in the parent form to refresh its data, or move to
the
> next record, by virtue of a filter.  So what code would I use to tell the
> usercontrol to do something.  Let's look at the details...
[quoted text clipped - 21 lines]
>
> Private Sub ddlMainLookup_SelectedValueChanged(ByVal sender As Object,
ByVal
> e As System.EventArgs) Handles ddlMainLookup.SelectedValueChanged
>         Me.panDesktop.Controls.Clear()
[quoted text clipped - 7 lines]
> As you can see, I'm having to clear the panel and reload it, which happens
> to yeild the results I need.  But this is rather slow and clumsy.  I need
to
> be able to invoke a method that tell puscTWExpenses to refresh/requery
it's
> data so it will show me the returns for matching header data in the parent
> form which lives in panDesktop.
[quoted text clipped - 6 lines]
> >
> >             Maybe you can use databinding

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/v
bnet02122002.asp


> > Ken
> > --------------------
[quoted text clipped - 11 lines]
> > REFETCH, of figure out a way to tell the underlying UserControl object
> > living in the panel to update whenever the parent record/combobox
changes.
> > Please help.
> >
> > John
Bonnie Berent [C# MVP] - 11 Apr 2005 01:49 GMT
John,

I think your best bet would be to use a DataView instead of a .Select() as
your DataSource. Then it's a simple matter of changing the RowFilter in your
SelectedValueChanged() event.

~~Bonnie

> Ken;
>
[quoted text clipped - 100 lines]
> > >
> > > John

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.