DataGridView 行验证错误

发布于 2024-11-03 11:11:11 字数 1542 浏览 2 评论 0原文

我使用非常奇怪的方式将我的数据从网格同步到数据库:

例如:

#region Line methods
private void LinesView_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
{
    lineTableAdapter.Update(fRIIBDataSet.Line);
}

private void LinesView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    lineTableAdapter.Update(fRIIBDataSet.Line);
}

private void LinesView_RowValidated(object sender, DataGridViewCellEventArgs e)
{
    lineTableAdapter.Update(fRIIBDataSet.Line);
}
#endregion

但是当我将一些列切换到组合框时,我需要在更新之前做一些类似的事情:

private void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
{
    //deltaTableAdapter.Update(fRIIBDataSet.Delta); TODO
}

private void dataGridView1_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
{
    deltaTableAdapter.Update(fRIIBDataSet.Delta);
}

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    if (lambdacat != null)
    {
        string selected = (LimView.Rows[e.RowIndex].Cells[1] as DataGridViewComboBoxCell).FormattedValue.ToString();
        if (selected != "")
        {
            int find = Array.IndexOf(dict, dict.Where(x => x == selected).FirstOrDefault());
            LimView.Rows[e.RowIndex].Cells[0].Value = dictiddarray[find];
            //deltaTableAdapter.Update(fRIIBDataSet.Delta);
        }
    }
    //deltaTableAdapter.Update(fRIIBDataSet.Delta);
}

取消注释更新方法后会出现麻烦。

当我打开带有表格的窗口时,我收到错误消息:内部索引 DataTable 已损坏:“5。”如何修复/避免此错误?

I'm sync my data from Grid to DataBase using really weird way :

for example :

#region Line methods
private void LinesView_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
{
    lineTableAdapter.Update(fRIIBDataSet.Line);
}

private void LinesView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    lineTableAdapter.Update(fRIIBDataSet.Line);
}

private void LinesView_RowValidated(object sender, DataGridViewCellEventArgs e)
{
    lineTableAdapter.Update(fRIIBDataSet.Line);
}
#endregion

but when I switched some columns to ComboBox I need to make some trick before Update alike that :

private void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
{
    //deltaTableAdapter.Update(fRIIBDataSet.Delta); TODO
}

private void dataGridView1_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
{
    deltaTableAdapter.Update(fRIIBDataSet.Delta);
}

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    if (lambdacat != null)
    {
        string selected = (LimView.Rows[e.RowIndex].Cells[1] as DataGridViewComboBoxCell).FormattedValue.ToString();
        if (selected != "")
        {
            int find = Array.IndexOf(dict, dict.Where(x => x == selected).FirstOrDefault());
            LimView.Rows[e.RowIndex].Cells[0].Value = dictiddarray[find];
            //deltaTableAdapter.Update(fRIIBDataSet.Delta);
        }
    }
    //deltaTableAdapter.Update(fRIIBDataSet.Delta);
}

troubles comes after uncommenting Update method.

When I opening the window with a table I've got error message : Damaged the internal index DataTable: "5. " How can I fix / avoid this error ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆夏时光 2024-11-10 11:11:11

修改成这样有用吗?

 if (selected != "")
    {
        int find = Array.IndexOf(dict, dict.Where(x => x == selected).FirstOrDefault());
        LimView.Rows[e.RowIndex].Cells[0].Value = dictiddarray[find];
         fRIIBDataSet.Delta.BeginInit(); //
         deltaTableAdapter.Update(fRIIBDataSet.Delta);
         fRIIBDataSet.Delta.EndInit();
    }

Does modifying it to this work ?

 if (selected != "")
    {
        int find = Array.IndexOf(dict, dict.Where(x => x == selected).FirstOrDefault());
        LimView.Rows[e.RowIndex].Cells[0].Value = dictiddarray[find];
         fRIIBDataSet.Delta.BeginInit(); //
         deltaTableAdapter.Update(fRIIBDataSet.Delta);
         fRIIBDataSet.Delta.EndInit();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文