2

I am quite new to WPF and XAML but my background is of ASP.NET and C# so I have a vague idea of how it works.

In .net, I can use the repeater, datalist, gridview, bind to them a DataTable and output from that DataTable. I am now wanting to do the same with WPF.

Basically, I want to display simple records from a database (preferably using a DataTable as I usually work with those). The list might be something like this with two columns

  • 1) Grey TV

    2) Red car

    3) Blue motorbike

I have looked around but I can't get a definitive answer on what control to use. Some people say ItemsControl and some people say DataGrid. Can anyone help me here?

Thanks in advance.

1 Answer 1

2

A DataGrid is used for displaying Table-like data (Per record multiple columns). An ItemsControl is used to display data using your own ItemTemplate, in which you are unlimited in how to represent the items and in what directions or alignments.

Another good useable control for you might be a ListView, which works just as a ListBox except it doesn't have any selection logic. And you can choose between four different ways of displaying your items using the View property (http://msdn.microsoft.com/en-us/library/system.windows.forms.view.aspx).

In your case I would suggest using a ListView.

To bind any items to the control, you have to set the DataContext on the UserControl or the Control itself. And then bind the ItemsSource property to a local List or Collection using the Binding markup extension (http://msdn.microsoft.com/en-us/library/ms750413.aspx). To learn more about data-binding go here:

http://msdn.microsoft.com/en-us/library/ms752347.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I took your advice with the ListView and managed to code a GridView inside that to show the data. Works O.K for what I want at the moment. No doubt i'll come back to this topic later.

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.