Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET DataTables, Events and determining if a specific column value has changed
    text
    copied!<p>I have a Table, called Table1, with 3 columns:</p> <p>1) id - An integer and the primary key</p> <p>2) Name - A string</p> <p>3) Flagged - A boolean</p> <p>In most cases any rows of Table1 will be have Flagged set to false. I'm interested in knowing when <em>any</em> row has a value set to true. For now, I've simply been using the query</p> <p>Table1.Select("Flagged = TRUE")</p> <p>However, I thought it may be possible to determine this using events. </p> <p>The code below with the DataColumnChangeEventHandler will give me a notification for any column changes. The Notification_ColumnChanged() method gets called three times since there are three lines in the method UpdateTable().</p> <p>I would prefer to only get a notification once and only if any rows in the Flagged column are modified and therefore I don't need to call a Select() method. I was wondering if this is possible? Perhaps DataViews and events based on those would be a better way to achieve this? I'm interested in any suggestions.</p> <p>Thanks.</p> <pre><code>using System; using System.Data; namespace ConsoleApplication1 { public class Program { private TestDataSet _testDataSet; public Program() { _testDataSet = new TestDataSet(); _testDataSet.Table1.AddTable1Row(1, "name1", false); _testDataSet.Table1.AddTable1Row(2, "name2", false); _testDataSet.Table1.AcceptChanges(); _testDataSet.Table1.ColumnChanged += new DataColumnChangeEventHandler(Notification_ColumnChanged); } private void Notification_ColumnChanged(object sender, DataColumnChangeEventArgs e) { Console.WriteLine("Notification_ColumnChanged"); } public void UpdateTable() { Console.WriteLine("Updating"); _testDataSet.Table1[0].Flagged = true; _testDataSet.Table1[1].Flagged = true; _testDataSet.Table1[1].Name = "name2"; } public static void Main(string[] args) { Program p = new Program(); p.UpdateTable(); } } } </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