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. Image for the cookie policy date
close icon

Error, Urgent Please do help!

Hi, I have griddataboundgrid attached to collection to business entity. I have Grid.eabledaddnew=true; Now when I retrieve the data from database I get 3 rows and collection have 3 rows. But my grid display one more empty row at the bottom, which is good. But as son as I type something in any of cell in 4th row I get the error message, probably because this row (4th) is not there in collection. Please find the attached file for error message. Please do help! Rick

error4.zip

15 Replies

AD Administrator Syncfusion Team November 17, 2005 02:21 AM UTC

Does your collection implement IBindingList and does it have IBindingList.AddNew implemented? If not, then you will have to turn off grid.EnableAddNew or you will have to write code to handle adding the row to your collection when your user enters the AddNew row. You can subscribe to the grid.RowEnter event and check if you are on the last row to decide whether you need to add a new item to your collection.
private void gridDataBoundGrid1_RowEnter(object sender, GridRowEventArgs e)
{
	if(this.gridDataBoundGrid1.Model.RowCount == e.RowIndex)
		Console.WriteLine("need to add new item");
}


AD Administrator Syncfusion Team November 17, 2005 08:22 AM UTC

Or you can transform your collection to a DataTable and bind that to the grid. I wrote my own generic transformation from collection of business entities to a DataTable and back using reflection. When using a DataTable you can also do column sort in the grid. Rune


AD Administrator Syncfusion Team November 17, 2005 06:02 PM UTC

Sorry my mistake, It is working now. New rows are working fine. I have another problem with eidt. Whenever I edit something on old rows my business entity is not updated with new values. Please suggest something. Thanks,


AD Administrator Syncfusion Team November 17, 2005 06:15 PM UTC

Exactly what is your business entity? What interfaces does it implement? If it is a IList of strongly typed objects with public properties, then normally, the item will be updated when you leave the grid row. If you are binding to some arbitrary array, then you might have to handle grid.Model.SaveCellInfo. In that event, based on e.RowIndex and e.ColIndex, you would store e.Style.CellValue into your datasource.


AD Administrator Syncfusion Team November 17, 2005 07:34 PM UTC

Clay, I have some more info for you. My object implementing the IBindList collection properly and my collection implement the IEditableObject. It looks like it works only if I leave the row/grid but not while doing a tab out from a cell. I need to force the the grid to set the values right away so that my business object can calculate other cell values. regrads,


AD Administrator Syncfusion Team November 17, 2005 07:41 PM UTC

Clay, I tried the following code and it looks like that grid is working. Please confirm that this is the right way. private void gdbgSalary_CurrentCellAcceptedChanges(object sender, System.ComponentModel.CancelEventArgs e) { this.gdbgSalary.CurrentCell.EndEdit(); this.gdbgSalary.Binder.EndEdit(); }


AD Administrator Syncfusion Team November 17, 2005 07:44 PM UTC

Two more Issues! #1 Delete key doesn''t work withing the cell, in order to delete few letters? #2 How can i stop user to entering the invalid values(string in int and int in string)? Thanks,


AD Administrator Syncfusion Team November 17, 2005 08:02 PM UTC

The delete key works OK when you select some text in cell in this sample using version 3.3. http://www.syncfusion.com/Support/user/uploads/GDBG_DeleteKey_4015581b.zip What are you doing differently? Do you have any menu or toolbar items that might be using the Delete as a hotkey? If so, then that will eat thos keystroke so the grid does not get it. Is the cell set to be readonly? That would prevent the delete from working.


AD Administrator Syncfusion Team November 17, 2005 08:11 PM UTC

Clay, Please confirm the binding solution i sthe right way? Please confirm that this is the right way. private void gdbgSalary_CurrentCellAcceptedChanges(object sender, System.ComponentModel.CancelEventArgs e) { this.gdbgSalary.CurrentCell.EndEdit(); this.gdbgSalary.Binder.EndEdit(); }


AD Administrator Syncfusion Team November 17, 2005 08:25 PM UTC

The code you added in CurrentCellAcceptedChanges will force the grid to raise the IBindingList.ListChanged event on the datasource. The default behavior of the grid is to only raise this event when you leave the row. If you want it raised with every change even if you do not leave the row, then your code is OK.


AD Administrator Syncfusion Team November 17, 2005 09:41 PM UTC

Thanks clay, I am not using any hot key on my form. i am attached entire code for my grid from form.. Please see if you could find something. thanks,

gridcode0.zip


AD Administrator Syncfusion Team November 17, 2005 10:20 PM UTC

I did not see anything. You are talking about a TextBox cell and not a ComboBox cell. For your combobox cells, you have them set to Exclusive which means you can only enter values fdrom the list. This might affect the delete key behavior. If you can upload a sample project showing the problem, we can try to debug it.


AD Administrator Syncfusion Team November 18, 2005 08:47 AM UTC

I guess i might know the problem. When I am pressing the ''Del'' key the current row is still selected. Grid #1 where ‘0’ column is not hidden, I can see the arrow for row selection. As soon as I press ''del'' key the row gets deleted from the grid. Grid # 2 As soon as I press ''del'' key, basically nothing happens, I mean it nothing happens even row doesn’t get deleted (because IbindList.AllowRemove =false). Does this give you any idea, why ‘Del’ ke is nt working properly?


AD Administrator Syncfusion Team November 18, 2005 10:29 AM UTC

Are you using version 3.3? What version of our libraries are you using? The delete key not deleting selected text, but deleting the whole row instead was a behavior in our earlier versions, but should work in 3.3. Here is some work-around code that may handle this problem for you - but you may have to set AllowRemove true for th eevent to be hit. (You can always set e.Cancel in the event to prevent all deletecions instead of relying on this property.) private void gridDataBoundGrid1_RowsDeleting(object sender, GridRowRangeEventArgs e) { if(this.grid.CurrentCell.IsEditing) { e.Cancel = true; GridTextBoxControl tb = this.grid.CurrentCell.Renderer.Control as GridTextBoxControl; if(tb.SelectionLength == 0) tb.SelectionLength = 1; tb.SelectedText = ""; } }


AD Administrator Syncfusion Team November 18, 2005 07:22 PM UTC

Thanks clay, I am using 3.0.1.1. no plan for upgrade. I am still having the following problem, even though i set the allowremove=true. it doesn''t do anything when i press ''Del'' key. Grid # 2 As soon as I press ''''del'''' key, basically nothing happens, I mean it nothing happens even row doesn’t get deleted. Thanks,

Loader.
Live Chat Icon For mobile
Up arrow icon