0

我有一个 GridControl 插入其中,直接修改到数据库中。

我有几个字段直接连接到一个表Patient,我的 gridcontrol 字段之一idespecielistas 1 TableSpecialist which has a 1:1 RelationshipEsp-> MuchosPacientes and this field shows you allID 专家and lets me do the main functions. But to eliminate me says no sender == null,但实现了相同的代码,但针对 1 个事件KeyDown并且它是否完全删除sender != null,可以是:

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);
    }
}
4

2 回答 2

1

原因是,gridView1_KeyDown如果发送者是gridView1这样,当您投射到 GridView 时 - 一切都很好。

因此,如果gridControl1_EmbeddedNavigator_ButtonClick您的发件人是gridControl1,当您从发件人投射时,您会得到null

尝试转换为 GridControl 然后获取 Views 或重命名gridView1为更具解释性的名称并直接引用它。

于 2013-01-20T10:05:48.250 回答
1

您是否尝试过使用“gridView1”而不是“view”(来自“sender”)?

于 2013-01-19T16:39:42.437 回答