المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : display detail view form when click on a row



C# Programming
12-30-2009, 06:29 PM
Hi. I would like to be able to bring up another form for editing data in Detail view when click on a row in gridview. these or the code that i'm workin with but don't seem to be working. Anyone help me or show me another easier way to do it

// EmployeesViewForm.cs ////This the GridviewForm
class EmployeesViewForm : Form {
...
void addToolStripButton_Click(object sender, EventArgs e) {
this.EditEmployee(this.employeesBindingSource.AddNew());
}

void updateToolStripButton_Click(object sender, EventArgs e) {
this.EditEmployee((DataRowView)this.employeesBindingSource.Current);
}

void EditEmployee(DataRowView item) {
// Pass to child employee details form
EmployeesEditForm dlg = new EmployeesEditForm(item);
if( dlg.ShowDialog() == DialogResult.OK ) {
// Reset to reflect changes automatically
this.employeesBindingSource.ResetCurrentItem()
}
}

// EmployeesEditForm.csartial class EmployeesEditForm : Form {
...
public EmployeeItemForm(object item) {

// Check that item is a DataRowView for an EmployeesRow
if( (item is DataRowView) &&
(((DataRowView)item).Row is NorthwindDataSet.EmployeesRow) ) {
InitializeComponent();

// Acquire employee list data source item
this.employeesBindingSource.DataSource = item;
}
else throw new ArgumentException("Incorrect type");
}
...
}

// EmployeesEditForm.cs //// This the form with detail View
partial class EmployeesEditForm : Form {
...
void EmployeeItemForm_FormClosing(
object sender, FormClosingEventArgs e) {
// Cancel edit if Cancel button is pressed or form is closed from
// either the system menu or close box
if( (e.CloseReason == CloseReason.UserClosing) ||
(this.DialogResult == DialogResult.Cancel) ) {
this.employeesBindingSource.CancelEdit();
}
}
}