Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i have a datagrid bound to a table. i am adding and deleting records using the datagrid. here is the code behind my delete button:

 


private void button4_Click(object sender, System.EventArgs e)
	{
		int dfd =  ds.Tables["visit_activities"].Rows.Count;
		foreach(DataRow r in ds.Tables["visit_activities"].Rows)
		{
			if(r.RowState == DataRowState.Deleted)
			{
				dfd = dfd - 1;
			}
			
		}
		if(dfd >= 0)
		{
			int i = this.dataGrid1.CurrentRowIndex;
			DataRow row = ds.Tables["visit_activities"].Rows[i];
			row.Delete();
			ds.Tables["visit_activities"].Rows.Remove(row);
			
			this.dataGrid1.Refresh();
		}
		else {}
	}

the problem is that this works most of the time, except sometimes when it doesnt remove the row as its still visible in the grid, yet it does not throw an error.i select the row i want to delete, click delete, all the code executes but nothing seems to happen. it happens when im down to 2 records left displayed in the dataGrid. can anyone tell me what might be happening

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...