We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Multiline Display and deleting records

Thread ID:

Created:

Updated:

Platform:

Replies:

37649 Nov 28,2005 12:30 PM Nov 29,2005 06:41 AM Windows Forms 7
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On November 28, 2005 12:30 PM

I am using the Databound Grid control and using a multi-line display. Selection is limited to row or cell. When a row is selected (would be nice to select the record not the row), and I press delete it seems almost pot luck whether or not the action will be ignored or cause an unhandled exception to be thrown. So I added the rows_deleting event and manually got the row and deleted it. Then set cancel to true and told the grid to refresh. int row = grid.Binder.GetRecordStateAtRowIndex(index).Position; dv[row].Delete(); e.Cancel = true; grid.Refresh(); This will typically work the first time and then throw an exception, after my code is done executing, the second time saying: System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.QueryCellInfo(GridQueryCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.GetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetViewStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridControlBase.GetPaintStyleInfo(Int32 rowIndex, Int32 colIndex, Boolean forceQueryCellInfo) at Syncfusion.Windows.Forms.Grid.GridPaint.InternalLoadCell(DrawStruct ds, Int32 rowIndex, Int32 colIndex) at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) rectClip) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridPaint.DrawClientRowCol(Int32 topRow, Int32 leftCol, Int32 bottomRow, Int32 rightCol, Graphics g, Rectangle rectClip) in :line 0 An unhandled exception of type ''System.IndexOutOfRangeException'' occurred in system.data.dll Additional information: Index -1 is not non-negative and below total rows count.

Administrator [Syncfusion]
Replied On November 28, 2005 12:54 PM

Does this only happen if you are removing the last record? If so, try moving the current position before you . Use code like: CurrencyManager cm = grid.BindingContext[grid.DataSource, grid.DataMember] as CurrencyManager; if(row == dv.Count - 1 && cm.Position == row) { cm.Position -= 1; } dv[row].Delete();

Administrator [Syncfusion]
Replied On November 28, 2005 01:10 PM

Nope it happens if I have 3 rows and delete the first row then delete the first of the remaining rows.

Administrator [Syncfusion]
Replied On November 28, 2005 01:17 PM

For an example of the problems with this issue take the multirowrecord sample for databoundgrids and change the following line: this.gridDataBoundGrid1.AllowSelection = GridSelectionFlags.None; to allow .Row instead of none then try deleting a row. Delete the second record then attempt to delete the first record. I am not sure if the second record is actually deleted but trying to delete the first will then throw an exception (make sure to check multiline display firsT).

Administrator [Syncfusion]
Replied On November 28, 2005 02:03 PM

I am able to avoid this problem in the sample using code like:
private void gridDataBoundGrid1_RowsDeleting(object sender, GridRowRangeEventArgs e)
{
	this.gridDataBoundGrid1.BeginUpdate();
	
	e.Cancel = true;

	GridBoundRecordState state = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.To);
	CurrencyManager cm = this.gridDataBoundGrid1.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember] as CurrencyManager;

	this.gridDataBoundGrid1.Binder.LayoutColumns(
		new string[] {
							"CustomerID",
							"CompanyName",
							"ContactTitle", 
							"ContactName", 
							"Address",
							"City",
							"PostalCode",
							"Country",
							"Phone",
							"Fax",
							"Region"
						});

	cm.RemoveAt(state.Position);
	this.gridDataBoundGrid1.Binder.LayoutColumns(
		new string[] {
							"CustomerID",
							"CompanyName", "-",
							"ContactTitle", 
							"ContactName", "-",
							".", 
							"Address", "-", "-",
							"City", "-", "-",
							".", 
							"PostalCode",
							"Country", "-",
							"Phone",
							"Fax",
							"Region"
						});
	cm.Position = state.Position;
	this.gridDataBoundGrid1.EndUpdate();
	this.gridDataBoundGrid1.Refresh();
}

Administrator [Syncfusion]
Replied On November 28, 2005 02:38 PM

That works thanks. Is there plans to address this with a bug fix? Has this been logged as an error or do I need to do that somewhere.

Administrator [Syncfusion]
Replied On November 28, 2005 02:49 PM

One last thing... In your sample you need to check if the state.position exists otherwise it will throw an exception (ie on the new row).

Administrator [Syncfusion]
Replied On November 29, 2005 06:41 AM

We have entered this in our defect database. http://www.syncfusion.com/support/issues/grid/Default.aspx?ToDo=view&questId=1120 It has been corrected here in our code base and the correction should be in the next public build (4.1.0.0). (I do not have a date for this yet but it is in the works.) With the corrected code, you may not need a RowDeleting event handler at all. As long as records are selected, you can press delete and remove them. In some setting, pressing the delete will remove the selection, so in that case, pressing delete will not remove a record but will edit the cell. If you do not want this behavior, then you can add a RowDeleting handler and always make sure a record is selected so the delete will work as expected. Here is a snippet to show this might be done. (But you will need the 4.1 code base to test it out.)
private void gridDataBoundGrid1_RowsDeleting(object sender, GridRowRangeEventArgs e)
{
	if(this.gridDataBoundGrid1.Selections.GetSelectedRows(true, false).Count == 0)
	{
		GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
		int top = cc.RowIndex / this.gridDataBoundGrid1.Binder.GetHierarchyLevel(0).RowCountPerRecord;
		int bot = top + this.gridDataBoundGrid1.Binder.GetHierarchyLevel(0).RowCountPerRecord - 1;
		this.gridDataBoundGrid1.Selections.SelectRange(GridRangeInfo.Rows(top, bot), true);
	}
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;