Multiple selections mapped to one TextBox

May 6, 2009 at 1:33 AM
Edited May 6, 2009 at 4:27 PM
Hi,
I have been trying to achieve the following, but have had no success...  I hope somebody out there has an idea.  Here's the scenario:

I have a DataGrid where each row (master) can have its details examined in a form below the table.  TwoWay Binding is employed to map each row to the the form.  When a single row is selected, all is well: the details are properly displayed.  But when multiple rows are selected, I need to display the data in the form as follows:
1. if the values from the same column are the same, show the value in the form
2. if the values from the same column are different, show no value in the form
2a. if the user enters a value in the form, with multiple rows selected, propagate that value to all the selected rows.

e.g.

First Name

Last Name

John

Smith

Josh

Smith

       
Let's say my form simply contains 2 text boxes, A and B. 
If I select row0 above, the text boxes would show the proper values: A=John and B=Smith.
If I select row0 and row1 above, the text boxes need to show the values: A=? and B=Smith.
If I then change the value in A from ? to Jeff, then both rows in the table get updated such that the First Name becomes Jeff.

How do I go about setting that up?  Multibinding?  Unsure as how best to proceed.  Any guidance is appreciated.

Thanks very much!
E.

May 8, 2009 at 11:15 PM

In case anyone finds this post and wonders about a solution:

I ended up creating a converter class (implement IValueConverter).  The Convert method received an IList as a value (that is what I had attached as the Binding Path).  Using LINQ, I distilled the elements, column wise, into IEnumerables.

e.g.
IEnumerable<string> firstNames = (from person in list select person.FirstName).Distinct();
where list is an IList of Person elements

if firstNames.Count() == 1, I had a single value, otherwise multiple.  then I set the element value accordingly and returned it as the Convert method's value.  The IList passed in here was saved as an attribute of the converter instance.

the ConvertBack method used the saved IList to propagate any edited values back to the original.

e.