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.
Syncfusion Feedback

How to add/remove and set default values dynamically from griddataboundgrid

Thread ID:

Created:

Updated:

Platform:

Replies:

75073 Jul 10,2008 11:16 PM UTC Jul 24,2008 03:52 AM UTC Windows Forms 1
loading
Tags: GridControl
Alex Maldonado
Asked On July 10, 2008 11:16 PM UTC

Hi Whats the proper way to add and remove rows from the gdbg? I fixed a few errors I was having before but now I'm getting this error I'm I don't know how to fix it.

"Index 0 is not non-negative and below total rows count."

This is my current flow and it used to work before:

1. Create dataset schema with tables (tables are now empty)
2. Dynamically create grid and added to form/panel. Bind empty tables. Note grid has dropdownlist that is bind to another table.
3. Add data to tables.

Add/Remove flow:
1. User click on the empty table cell and select a dropdown value. Immediatly default values are set. I set them from RowEditing event.
2. Another empty row is added at the bottom.

1. Removing a cell I have a image on the row that when click I remove the clicked row.


Other things to watch:
If user is editing a row and clicks outside of the grid I want the row to be saved or pushed to the datasource.

1. I don't want user presing escape
2. I don't want user dragging a row out the grid.


Validation:
I need a centralize way to handle all validation if possible.
1. I need a validation when user select something from the dropdown list in one of the cells. (On selected event would be nice).
Also if dropdown is editable (user types the selection) then I also need an event for that.
2. I need validation when user enters text.

I'm currenly able to do most of stuff I mention, the problem is that I think I don't have the correct event handlings. Or the correct checks to handle databinding correctly. Therefore I'm getting weird error here and there.

Your prompt help would be greatly appricated.

-- Alex


SubhaSheela R [Syncfusion]
Replied On July 24, 2008 03:52 AM UTC

Hi Alex,

Thanks for your interest in Syncfusion products.

DataBoundGrid(GDBG) is a bounded grid which just displays the content from the datasource. So, if you wish to add or remove rows in gdbg, then you should actually add/remove rows from the binded datasource, so the grid reflects the same.

To delete any arbitary row, simply use the below code:

this.gridDataBoundGrid1.EnableRemove = true;
this.grid.DeleteRecordsAtRowIndex(rowindex, rowindex);

The recommended way is to use the Binder.RemoverRecords method to delete rows.

DataTable table = (DataTable) gridDataBoundGrid1.DataSource;
int curRowIndex = gridDataBoundGrid1.CurrentCell.RowIndex;
if (gridDataBoundGrid1.Model.RowCount > 1 && curRowIndex > 0 && gridDataBoundGrid1.Model.RowCount > curRowIndex )
{
int recNumber = this.gridDataBoundGrid1.Binder.RowIndexToPositioncurRowIndex);
this.gridDataBoundGrid1.Binder.RemoveRecords(recNumber, recNumber);
}

If you are having hierarchical relationship in grid, then refer the below forum thread to delete rows in hierarchical grid.

http://www.syncfusion.com/support/forums/message.aspx?MessageID=59847

To do any validation stuff on cell, the best event to handle is CurrentCellValidating event of grid. In this event you can get the Text or value that is entered from grid.CurrentCell.Renderer.ControlText and valiadte it. Please check the kb article below on validation.

http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=340

If you like to do any key based validations, then you may go for CurrentCellKeyPress/CurrentCellValidateString events.

Please let me know if you need any further assistance.

Regards,
Subhasheela R



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.

Warning Icon 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.Close Icon

;