deleting last row problem in DataGrid bound to ArrayList

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Thomas via DotNetMonster.com (forum_at_DotNetMonster.com)
Date: 01/26/05


Date: Wed, 26 Jan 2005 10:59:22 GMT

Hi

I have a big problem with my ArrayList and the DataGrid when I delete the last row. The actual deletion from the array and dataset works.
But the position indicator in the grid is lost and then if I click somewhere in the grid I get an exception.

This is my code for my delete button. Plus the updategrid that I found in another thread in this forum to refresh the grid.

By the way if my grid is empty the header columns does not show, even though I have initialized my variable in my list class. (Which I read somewhere that was needed to fix the empty header)

Can anyone help me?

private void deleteArrayList(DataMapping dm,System.Data.DataSet ds,string showTable)
{
   int removeAt = ((UserControlWinGrid)this.getCurrentUserControl()).getDataGrid().CurrentCell.RowNumber;

   dm.arrayList.RemoveAt(removeAt);
   cs = (CurrencyManager)this.BindingContext[dm.arrayList];
   cs.Refresh();
   this.BindingContext[ds,showTable].RemoveAt(removeAt);
   this.updateGrid(dm,removeAt-1);
}

private void updateGrid(DataMapping dm,int row)
{
 DataGrid dgTheGrid = (UserControlWinGrid)this.getCurrentUserControl()).getDataGrid();

  if (null != dgTheGrid)
  {
     dgTheGrid.DataSource = null;
     dgTheGrid.Refresh();

     cs = (CurrencyManager)this.BindingContext[dm.arrayList];
     cs.Refresh();

     dgTheGrid.DataSource = dm.arrayList;
     if(row < 0 && cs.Count > 0)
        row = 0;

     if(cs.Count > dgTheGrid.CurrentRowIndex)
        dgTheGrid.CurrentRowIndex = row;

     dgTheGrid.Refresh();
    }
}

-- 
Message posted via http://www.dotnetmonster.com

Quantcast