Solved

WPF Database CollectionViewSource Question

Posted on 2010-08-20
2
854 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

867 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

26 Experts available now in Live!

Get 1:1 Help Now