开发者

The given DataRow is not in the current DataRowCollection

开发者 https://www.devze.com 2023-03-31 12:34 出处:网络
m new in c#.m working on C# and .net.Iam stuck with this prob for two month.when i deleting row from gridview it gives error The given DataRow is not in the current DataRowCollection.

m new in c#.m working on C# and .net.I am stuck with this prob for two month.when i deleting row from gridview it gives error The given DataRow is not in the current DataRowCollection.

try
{
          if (dgvLetterSent.CurrentRow.Index != -1)
          {
              BindingManagerBase bm = dgvLetterSent.BindingContext[dgvLetterSent.DataSource, dgvLetterSent.DataMember];
              DataRow dr = ((DataRowView)bm.Current).Row;    

              if (dr[7].ToString() != "Not Specified")
              {
                  MessageBox.Show("Cannot remove the letter once it has been printed.", "NPB Database", MessageBoxButtons开发者_StackOverflow社区.OK);
              }
              else
              {
                  dtInviteLetter.Rows.Remove(dr);//this give me exception that The given DataRow is not in the current DataRowCollection.
                  dtInviteLetter.AcceptChanges();
                  fetchPaymentDetails();
               }
          }
}
catch { }


Both datarows come from different sources? So it's normal that you're getting this error.

You can only remove rows from dtInviteLetter that are members of the DataRowCollection of dtInviteLetter.

0

精彩评论

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