|
-
Jan 30th, 2004, 10:39 AM
#1
Thread Starter
Junior Member
refreshing a datagrid when item deleted
I have a datagrid which i am filling up on form load.
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dsCoops1);
}
I have ADD, MODIFY, DELETE and REFRESH buttons on this form and the triggered functions do their job well.
The problem comes when I try to make the datagrid reflect the changes (REFRESH button). If I add or modify, I can do a refill (like on form load) of the dataset and the changes automatically show up in the datagrid. BUT, when I delete a row from the datasource, the refill doesnt work since the Fill() only seems to update and add rows but not remove them from the dataset.
Ive tried various approaches to this and none work. Doing a Clear() on the dataset before refilling works except that for some reason when i try to get the CurrentRowIndex from the datagrid it always returns a '0'.
Code:
dsCoops1.Clear();
sqlDataAdapter1.Fill(dsCoops1);
Other stuff Ive tried:
Code:
sqlDataAdapter1.Fill(dsCoops1);
dataGrid1.Refresh() // tried Update() too
Thanks to anyone who can help!
*eanatum*
-
Jan 30th, 2004, 08:15 PM
#2
Frenzied Member
Just rebind the datagrid.
-
Feb 4th, 2004, 10:24 PM
#3
New Member
maybe you could try this line for your delete method:
dataTable1.Rows[dataGrid1.CurrentRowIndex].Delete();
-
Feb 5th, 2004, 03:34 AM
#4
Sleep mode
Originally posted by byteArray
maybe you could try this line for your delete method:
dataTable1.Rows[dataGrid1.CurrentRowIndex].Delete();
The problem will still be there .
For a fix , as DveGrp said , after you delete the record , refill the dataset and rebind it again .
-
Feb 5th, 2004, 03:39 AM
#5
Sleep mode
One more thing , Refresh and Update methods of the DataGrid are only for graphically redrawing the Grid not for updating data .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|