1

I have two ObservableCollection

List1 = new ObservableCollection<ManagementFunctionModel>();

List2 = new ObservableCollection<ManagementFunctionModel>();

Both these lists have their own data. In my xaml, is it possible to bind my Datagrid to two the two different lists? Ideally I want to bind List1 on button1click and List2 on button2click. My xaml is below

<DataGrid Name="grid" HorizontalAlignment="Stretch" ItemsSource="{Binding List1}" Margin="0,0,0,50" VerticalAlignment="Stretch" AutoGenerateColumns="False" CanUserAddRows="False">
  <DataGrid.Columns>
    ...
    ...
  </DataGrid.Columns>
</DataGrid>
1
  • 3
    Can't you set your Itemsourcein the code-behind in the click-handlers? Commented Jan 15, 2015 at 8:03

1 Answer 1

1

You cannot set the ItemsSource twice on a single DataGrid to two different lists.

You can however create a new custom class which will hold both of your ManagementFunctionModel objects in a single class:

public class ManagementFunctionPair
{
   public ManagementFunctionModel First { get; set; }
   public ManagementFunctionModel Second { get; set; }
}

Then, use an ObservableCollection of ManagementFunctionPair, and bind that to your DataGrid instead:

list = new ObservableCollection<ManagementFunctionPair>();
Sign up to request clarification or add additional context in comments.

1 Comment

OP, has this answer solved your problem? Are you still having trouble?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.