a DataTable with 4 columns and 5 rows. It then hooks up the RowChanged event handler. To add RowChanged, type table.RowChanged and then the += characters.
using System;
using System.Data;
class Program
{
static void Main()
{
DataTable table = new DataTable();
// ... Unique id.
table.Columns.Add(
"Id", typeof(int));
table.Columns[
"Id"].Unique = true;
table.Columns.Add(
"Dosage", typeof(int));
table.Columns.Add(
"Drug", typeof(string));
table.Columns.Add(
"Patient", typeof(string));
// ... Five DataRows.
table.Rows.Add(1, 25,
"Evista",
"Lundberg");
table.Rows.Add(2, 50,
"Adcirca",
"Jeffries");
table.Rows.Add(3, 10,
"Glucagon",
"Johnson");
table.Rows.Add(4, 20,
"Amyvid",
"Skinner");
table.Rows.Add(5, 80,
"Alimta",
"Nguyen");
table.AcceptChanges();
// ... Handle RowChanged.
table.RowChanged += table_RowChanged;
// ... Change a row.
table.Rows[0][
"Dosage"] = 50;
table.Rows[0][
"Dosage"] = -1;
// ... Pause.
Console.WriteLine(
"[Press enter]");
Console.ReadLine();
table.Rows[0][
"Dosage"] = 15;
table.Rows[1][
"Dosage"] = 800;
}
static void table_RowChanged(object sender, DataRowChangeEventArgs e)
{
Console.WriteLine(
"... Changed: " + (int)e.Row[
"Dosage"]);
}
}
... Changed: 50
... Changed: -1
[Press enter]
... Changed: 15
... Changed: 800