开发者

DataGridView RowValidation Error

开发者 https://www.devze.com 2023-03-01 04:41 出处:网络
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)

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 ne开发者_JAVA百科ed 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 ?


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();
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消