I have one GridControl in which I inserted, modified directly to the database.
I have several fields directly connected to a table Patient
and one of my gridcontrol field is the id
that was especielistas 1
Table
Specialistwhich has a 1:1 Relationship
Esp-> MuchosPacientesand this field shows you all
ID specialistsand lets me do the main functions. But to eliminate me says no sender == null
, but implement the same code but for 1 event KeyDown
and does it perfectly removed and sender != null
which can be:
private void gridControl1_EmbeddedNavigator_ButtonClick(
object sender,
NavigatorButtonClickEventArgs e)
{
if (e.Button.ButtonType == NavigatorButtonType.Edit
|| e.Button.ButtonType == NavigatorButtonType.EndEdit)
{
ColumnView view = gridControl1.FocusedView as ColumnView;
view.CloseEditor();
if (view.UpdateCurrentRow())
{
pacienteTableAdapter.Update(dBDataSet);
}
}
else if (e.Button.ButtonType == NavigatorButtonType.Remove)
{
if (MessageBox.Show("Desea eliminar?", "Confirmación", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
GridView view = sender as GridView; //AQUI ES EL ERROR
view.DeleteRow(view.FocusedRowHandle);
pacienteTableAdapter.Update(dBDataSet);
}
}
private void gridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (MessageBox.Show("Desea eliminar?", "Confirmación", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
GridView view = sender as GridView;
view.DeleteRow(view.FocusedRowHandle);
pacienteTableAdapter.Update(dBDataSet);
}
}