Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pass Data from Parent window to query in Child Window

Posted on 2010-08-16
8
Medium Priority
?
992 Views
Last Modified: 2013-11-12
Hi experts..

I have a silverlight page which has a list of users (for example) and I am trying to get it so that when i click on it, a child window appears and within that window there is another datagrid that is to be populated with data from tables based on the user i selected from the list box.

I am having difficultly passing userID to the wcf query behind the datagrid in the child window. The datagrid returns empty.

could you please correct me in where i am going wrong please..the code i have is below

**this code i have in the MainPage.xaml for the listbox_selected changed event.**
            ServiceReference1.site test = (site)ListBox1.SelectedItem;
            ChildShowDeviceResults cmod = new ChildShowDeviceResults();
           
            cmod.DataContext = test;
            cmod.Show();

**in the ChildWindow I have placed a textbox just to see if i can bind a value to it from the datacontext from the MainPage. When i load the childwindow, i can see taht the textbox shows the actual id of the user i selected, but then when i try to run the Page_Loaded event, the query doesnt seem to take the value into its parameters**

 private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
            _ServiceClient client = new _ServiceClient();
            client.getResultsByIDCompleted += new EventHandler<getResultsByIDCompletedEventArgs>(client_getResultsByIDCompleted);
            client.getResultsByIDAsync(Convert.ToInt32(textBox1.Text));

        }

this does not seem to work.


any help would be much appreciated.
0
Comment
Question by:baz86
8 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33453259
Perhaps these examples/articles can help you further

Passing Values between forms in Silverlight
http://www.c-sharpcorner.com/UploadFile/prvn_131971/PassingValuesSilverlight11192008060441AM/PassingValuesSilverlight.aspx

Silverlight How To Pass Values Between Pages or Forms
http://www.xploredotnet.com/2009/12/silverlight-how-to-pass-values-between.html
0
 
LVL 21

Accepted Solution

by:
tovvenki earned 2000 total points
ID: 33453541
Hi,
Are you still having facing issues,
you can also pass the data through the constructor
ServiceReference1.site test = (site)ListBox1.SelectedItem;
            ChildShowDeviceResults cmod = new ChildShowDeviceResults(selectedsite);
in the child window's constructor get the values and use it to get the data from the service

Thanks and regards,
Venki
0
 

Author Comment

by:baz86
ID: 33453640
Hi Dhaest and tovvenkit,
Thank you both for your replies.
@Dhaest. The links were useful but as i'm a beginner in all this i'm not sure how i could work that with the list box in form 1.
@tovvenkit. Yes still having issues unfortunately. Would you please be able to expand on the code in both forms to what i should be looking to get because im having no luck. I can't seem to access the ID of the selected item and pass that on.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:baz86
ID: 33453702
This is the xaml for the first page and it shows how the structure of the list box for your information
<ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock x:Name="txtSiteID" Text="{Binding site_id}" Margin="5" Foreground="Red"/>
                                        <TextBlock Text="{Binding site_name}" Margin="5" Style="{StaticResource TitleBlock}"/>
                                        <TextBlock Text="{Binding site_postcode}" Margin="5" Style="{StaticResource TitleBlock}"/>
                                    </StackPanel>

                                </DataTemplate>
                            </ListBox.ItemTemplate>

Open in new window

0
 

Author Comment

by:baz86
ID: 33453796
On page1 i can set the .ItemSource for page2 as whatever is selected in the list box on page one. But I can't seem to pass say the USERID from the listbox into a query in page 2 each time i call a new instance of page 2....any ideas?
0
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 33458088
It sounds like you are trying to do master/detail linking.  This article walks you through it.
http://www.silverlight.net/learn/videos/all/simple-masterdetails-with-datagrid/
0
 

Author Comment

by:baz86
ID: 33468876
Hi tovvenki,
Your suggestion of passing the value in the constructor worked like a charm! Thanks!!
0
 

Author Closing Comment

by:baz86
ID: 33468881
suggestion of passing the value in the constructor worked like a charm! Thanks!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Loops Section Overview

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question