7.5. The DataGrid Control

To allow the user to select an employee row of the DataGrid, we must provide a button column. A button column can be any of three types: Select; Edit, Up date, Cancel; or Delete. Clicking on a specific button column raises its associated event. For example, the blank push-button in the leftmost DataGrid column is a button column of type Select. When the user clicks on it, a select event is raised. Here is the associated handler:

public void
DataGrid1_SelectedIndexChanged (object sender, EventArgs e)
{
   Label5.Text = "OK. Dialing: " +
          DataGrid1.SelectedItem.Cells[2].Text + " " +
          DataGrid1.SelectedItem.Cells[1].Text + " at " +
          DataGrid1.SelectedItem.Cells[4].Text + " with video ";
   Label5.Text += CheckBox1.Checked ? "on." : "off.";
}

To insert a button column in a data grid, click on the Columns property of a ButtonColumn object. Click the push-button. A window pops open. Click the + sign to the right of the Button Column entry. Click on Select, and then click the arrow push-button (>) between the Available columns and Selected columns elements. Fill in the text boxes as appropriate. Figure 7.3 provides a snapshot of a completed Columns property window.

Figure 7.3. Adding a Button Column to a Data Grid


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.226