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.
加载中,请稍侯......
精彩评论