Results 1 to 5 of 5

Thread: refreshing a datagrid when item deleted

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    30

    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*

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Just rebind the datagrid.

  3. #3
    New Member
    Join Date
    Jan 2004
    Posts
    7
    maybe you could try this line for your delete method:

    dataTable1.Rows[dataGrid1.CurrentRowIndex].Delete();

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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
  •  



Click Here to Expand Forum to Full Width