Help with Panel and User Control

J

John Cosmas

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
 
K

Ken Tucker [MVP]

Hi,

Maybe you can use databinding
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02122002.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
 
J

John Cosmas

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
 
K

Ken Tucker [MVP]

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
 
J

John Cosmas

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.
 
K

Ken Tucker [MVP]

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.
 
G

Guest

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
 

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

Top