I have a C# project have :
The XAML Code:
The normal way of getting your data into the listview would be through databinding. Databinding is the way that WPF uses to transport data between your view and your code.
All wpf controls that can show multiple items, like listview, listbox, combobox etc, has a ItemSource
property. By setting this property to an enumerable, the view will display each item in the collection.
By default, it will just render each item as a textblock showing the result of calling ToString() on each object. There are several ways of customizing this. In your case, you have defined columns with a GridView
and GridViewColumn
s. Each GridViewColumn
has a DisplayMemberBinding
which can be binded to the property you want to display in that column.
So...
I'm not sure how easy it will be for you to use this. As mentioned by others, you really should learn a little bit about binding in wpf, and the Model-View-ViewModel (MVVM) pattern. MVVM really helps keeping the code clean.
Anyways...
Your view could be changed to something like this:
I would change your fixed size array of patients to a ObservableCollection
. A collection that can grow in size is almost always better than a fixed size one. The ObservableCollection<>
has some extra tricks as well. It will notify the view whenever items are added or removed.
Take a look at wpftutorial.net. You will find a nice introduction to binding , MVVM and a lot more.