Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok the simplest way to handle <code>DataGrid</code> is by binding to an <code>ItemSource</code>.</p> <p>The example below shows how to bind your list and how changes upadte the DataGrid.</p> <pre><code>public partial class MainWindow : Window { private ObservableCollection&lt;ConnectionItem&gt; _connectionitems = new ObservableCollection&lt;ConnectionItem&gt;(); public MainWindow() { InitializeComponent(); ConnectionItems.Add(new ConnectionItem { Name = "Item1", Ping = "150ms" }); ConnectionItems.Add(new ConnectionItem { Name = "Item2", Ping = "122ms" }); } public ObservableCollection&lt;ConnectionItem&gt; ConnectionItems { get { return _connectionitems; } set { _connectionitems = value; } } private void button1_Click(object sender, RoutedEventArgs e) { // to change a value jus find the item you want in the list and change it // because your ConnectionItem class implements INotifyPropertyChanged // ite will automaticly update the dataGrid // Example ConnectionItems[0].Ping = "new ping :)"; } } public class ConnectionItem : INotifyPropertyChanged { private string _name; private string _ping; public string Name { get { return _name; } set { _name = value; NotifyPropertyChanged("Name"); } } public string Ping { get { return _ping; } set { _ping = value; NotifyPropertyChanged("Ping"); } } public event PropertyChangedEventHandler PropertyChanged; /// &lt;summary&gt; /// Notifies the property changed. /// &lt;/summary&gt; /// &lt;param name="property"&gt;The info.&lt;/param&gt; public void NotifyPropertyChanged(string property) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(property)); } } } </code></pre> <p>Xaml:</p> <pre><code>&lt;Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication4" xmlns:properties="clr-namespace:WpfApplication4.Properties" Title="MainWindow" Height="300" Width="400" Name="UI" &gt; &lt;Grid&gt; &lt;DataGrid Name="dataGridView" ItemsSource="{Binding ElementName=UI,Path=ConnectionItems}" Margin="0,0,0,40" /&gt; &lt;Button Content="Change" Height="23" HorizontalAlignment="Left" Margin="5,0,0,12" Name="button1" VerticalAlignment="Bottom" Width="75" Click="button1_Click" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>i added a button to show how the data updates when you change something in your list, The class ConnectionItem is where you will store all your info for the datagrid.</p> <p>Hope this helps</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload