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

x
?
Solved

WPF Database CollectionViewSource Question

Posted on 2010-08-20
2
Medium Priority
?
868 Views
Last Modified: 2013-12-17
I'm a WPF newbie so go easy on me.

Generally I've created a window to lookup a person in table.  After closing that window I want to display more information about that selected user.

In one dialog window I have used a DataGrid to select a row representing a person.
After selecting the person, I exit the dialog with the System.Data.DataRow information saved. In the calling dialog I have a CollectionViewSource that contains all of the people.  It seems like I should be able to use the row information that I've saved to move to the same row in the CollectionViewSource, but I can't find a way to do it.  Is there a better way to do this or is there just something that I'm missing?

//C# code saving the person in the find a person window.
selectedItem = dtgPerson.SelectedItem as FAPDataSet.TblPersonRow;

XAML CollectionViewSource binding to table
<CollectionViewSource x:Key="tblPersonViewSource" Source="{Binding Path=TblPerson, Source={StaticResource FAPDataSet}}" />

Thank you in advance for your help.




0
Comment
Question by:sbooth1117
2 Comments
 
LVL 13

Expert Comment

by:kaylanreilor
ID: 33509225
I suppose that you will have to navigate through your collection, for each item cast the CurrentItem as a FAPDataSet.TblPersonRow object and make a comparison (http://msdn.microsoft.com/en-us/library/ms754244.aspx).
Or you may want to implement a more complex procedure to allow some enhancement later on by using some filter, like allow a multi selection : http://bea.stollnitz.com/blog/?p=31.
0
 

Accepted Solution

by:
sbooth1117 earned 0 total points
ID: 33524735
I got it.  I just created a stored procedure that took a personID as the parameter.  Then after I find the person I do the following:

FAPDataSetTableAdapters.TblPersonTableAdapter dsFAPSearchTblPersonTableAdapter = new FAPDataSetTableAdapters.TblPersonTableAdapter();
dsFAPSearchTblPersonTableAdapter.FillBy(dsFAPSearch.TblPerson, person.PersonID);
System.Windows.Data.CollectionViewSource tblPersonViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("tblPersonViewSource")));
tblPersonViewSource.View.MoveCurrentToFirst();

Person.PersonID is ID of the person that has been selected and FillBy is the method that the disigner created based on the stored procedure that I created.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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