Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>You don't need ADO.NET DataTables when you don't use database</em>. Just add gridview to your form. Select your gridview, and at the bottom of properties window you'll see two links <code>Add Column...</code>, <code>Edit Columns...</code>. You can add required columns and set their types here.</p> <p>Assume you have following class:</p> <pre><code>public class City { public string Name { get; set; } public string Country { get; set; } public string CountryCode { get; set; } public string State { get; set; } } </code></pre> <p>Add four columns of type DataGridViewTextBoxColumn to your GridView with headers <code>Country:</code>, <code>Country Code:</code>, <code>State:</code>, <code>City:</code> (you can make columns readonly). Then go to <code>Edit Columns</code> and specify for each column DataPropertyName. It should be property name of your City class, to which column will be bound. E.g. it should be <code>Name</code> property for column <code>City</code>.</p> <p>Then create list of cities and assign it to GridView:</p> <pre><code>BindingList&lt;City&gt; cities = new BindingList&lt;City&gt;() { new City() { Name = "Carros", Country = "France", CountryCode = "FRA" }, new City() { Name = "Barcelona", Country = "Spain", State = "Catalonia" } }; dataGridView.DataSource = cities; </code></pre> <p>If you will use <code>BindingList</code> instead of simple <code>List</code>, then changes on your cities list will affect data in DataGrid (i.e. when you add or remove cities):</p> <pre><code>void ButtonAddCity_Click(object sender, EventArgs e) { cities.Add(new City() { Name = nameTextBox.Text, Country = countryTextBox.Text, CountryCode = codeTextBox.Text, State = stateTextBox.Text }); } </code></pre>
 

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