Deleting a Task
You now know everything you need to implement the functionality needed to delete a task. As before, add a button to MainForm
called deleteButton
with the title Delete Task
.
Double click on the new button to add a click event handler. Then add the following code which retreives the currently selected task by asking the dataSource
for Current
. It then displays a MessageBox
with the text including the title of the currently selected task. Finally if the user clicks OK then it removes it from the dataModule
and from the dataSource
.
private void deleteButton_Click(object sender, EventArgs e)
{
Tasks.Tasks currentTask = (Tasks.Tasks)this._dataSource.Current;
if (MessageBox.Show("Delete task: " + currentTask.Task + "?", "Delete a Task", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
{
return;
}
this._dataModule.DataAdapter.DeleteRow(currentTask);
this._dataSource.Remove(currentTask);
}
Remember that at this point the changes to the table are only made locally. To make them permenant you need to click the Apply Updates
button or apply the changes immediately, otherwise the next time the user presses Load Data
it will bring back the deleted task.
Now we should make a change to Relavity Server using server side scripting, so that it only returns Tasks that belong to the logged in user.