Solved

WPF Database CollectionViewSource Question

Posted on 2010-08-20
2
853 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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now