locked
Element with multiple dataBinding sources? RRS feed

  • Question

  • Hello,
    i'm having a little trouble with the dataBinding source of a combobox. Is there a way to use one source for the DisplayMemberPath property, meaning displaying items from one source, and a different source for the selectedItem property?  The scenario looks like the following (not the real thing, just example), i have one dataTable(for the comboBox items) with authors in it, and another table with books in it. the books are displayed in a listview and one can choose the author of the currently selected book via a comboBox (which is not part of the listbox). Now i need to show all authors in the comboBox and therefore the itemssource to the books dataTable, but i also need to point to the current book, like:
    Code Snippet

    ItemsSource="{Binding ElementName=ListView, Path=SelectedItem}" SelectedItem="{Binding Path=author}"


    but because i can only set one itemsSource, that doesn't work, setting an explicit source for the selectedItem property like
    Code Snippet

    SelectedItem="{Binding Source="{Binding ElementName=ListView, Path=SelectedItem}", Path=author}"


    is not possible. Another way would be to set the itemssource to point to the books dataTable and the dataContex to the listView selectedItem, but then again, i don't know how to use one property with the one source and another property of the explicitly with another. I've also tried an ItemTemplate, but i can't set a different source just for the template, can i?
    thx
    Wednesday, March 26, 2008 4:16 PM

Answers

  • Thanks for the advice, i solved it differently though.
    I played i little more around with the bindings of SelectedValue, SelectedValuePath, ItemsSource and DisplayMemberPath. In the end the source of the comboBox was still the whole dataSet and the itemsSource was simply set to the dataTable with the items and an appropriate DisplayMemberPath, all that worked before. All i did to connect the selected value to the listview was to set the SelectedValue to the dataTable, which was also source of the listview, and then to the value which should be connected, like this:
    SelectedValue="{Binding Path=Table1/name}"
    and then set the selectedValuePath to that value (name) as well. And the last important step was to set the listView and the comboBox to IsSynchronizedWithCurrentItem="True". That's why i don't need something like {Binding Path=SelectedItem} anymore, because this way it's done automatically.
    I hope this helps someone who may have a similar problem.
    Wednesday, March 26, 2008 7:48 PM

All replies

  • Check out material on Composite collections and binding to composite collections. I think this might help you.

     

    Wednesday, March 26, 2008 4:23 PM
  • Thanks for the advice, i solved it differently though.
    I played i little more around with the bindings of SelectedValue, SelectedValuePath, ItemsSource and DisplayMemberPath. In the end the source of the comboBox was still the whole dataSet and the itemsSource was simply set to the dataTable with the items and an appropriate DisplayMemberPath, all that worked before. All i did to connect the selected value to the listview was to set the SelectedValue to the dataTable, which was also source of the listview, and then to the value which should be connected, like this:
    SelectedValue="{Binding Path=Table1/name}"
    and then set the selectedValuePath to that value (name) as well. And the last important step was to set the listView and the comboBox to IsSynchronizedWithCurrentItem="True". That's why i don't need something like {Binding Path=SelectedItem} anymore, because this way it's done automatically.
    I hope this helps someone who may have a similar problem.
    Wednesday, March 26, 2008 7:48 PM