User (Old forums)MemberMay 8, 2007 at 6:04 amPost count: 23064
I have a grid witch datasource is a DataTable, with three colums, two of them readonly and a third editable with the events LeavingEdit and ValidationError.
The problem is when i enter edit in a cell, change the numeric value (or not), and leave the cell with a mouse click. Then, the code in LeavingEdit executes and, at the end (in the } statement), it fires and exception with this Message, Source and StackTrace:
“An attempt was made to select a row that does not belong to a grid.\r\nXceed.Grid\r\n at Xceed.Grid.Row.SetSelected(Boolean isSelected)\r\n at Xceed.Grid.Collections.SelectedRowList.ResetTo(Row row)\r\n at Xceed.Grid.GridControl.DoRowSelections(Row oldCurrentRow, Row newCurrentRow, Keys modifierKeys, Boolean rowChangedWithMouse)\r\n at Xceed.Grid.MasterGrid.SelectWithMouse(VisualGridElement gridElement, MouseButtons button, Point mousePosition, Boolean allowCellEdition)\r\n at Xceed.Grid.Cell.OnMouseDown(MouseEventArgs e)\r\n at Xceed.Grid.GridControl.DoMouseDown(MouseEventArgs e)\r\n at Xceed.Grid.GridControl.OnMouseDown(MouseEventArgs e)\r\n at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at Xceed.Grid.GridControl.WndProc(Message& m)\r\n at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n at GestorIncidencias.frmPrincipal.Main(String args) in frmprincipal.cs:line 1273”
Code in cell_LeavingEdit, makes a complete actualization of the grid (grid.Clear(), reasingnates the DataSource and fill the grid with its characteristics and rows) and then makes the current row being editing as the selected row. Code in cell_ValidationError never executes.
I also have code in cell_MouseDown and in cell_Click, but the execution line never reaches that code.
If i press Enter or Scape to end the edition no problem happens.
I have initially installed the xceed.grid version 2.5 and after changing to version 3.2, the problem is still alive.
Any help would be appreciated. Thanks.
Note: sorry about my bad english.
Imported from legacy forums. Posted by Javier (had 3593 views)User (Old forums)MemberMay 8, 2007 at 5:24 pmPost count: 23064
This will not work. If you reset the grid, the sender row of the LeavingEdit event is not valid anymore.
What you need to do is to search for the corresponding row (through the value of one cell for example) in the new row list, and set it as the current one. You will need to use the Application.Idle event for this to work.
private void Form1_Load(object sender, System.EventArgs e)
foreach( Cell cell in dataRowTemplate1.Cells )
cell.LeavingEdit += new LeavingEditEventHandler( cell_LeavingEdit );
private Int32 supplierID;
private void cell_LeavingEdit( object sender, LeavingEditEventArgs e )
Cell cell = sender as Cell;
if( cell != null )
e.Cancel = true;
supplierID = ( Int32 )cell.ParentRow.Cells[ “SupplierID” ].Value;
gridControl1.DataSource = suppliersBindingSource;
Application.Idle += new EventHandler( Application_Idle );
private void Application_Idle( object sender, EventArgs e )
Application.Idle -= new EventHandler(Application_Idle);
foreach( Xceed.Grid.DataRow row in gridControl1.DataRows )
if( ( Int32 )row.Cells[ “SupplierID” ].Value == supplierID )
gridControl1.CurrentRow = row;
gridControl1.SelectedRows.Add( row );
Imported from legacy forums. Posted by André (had 419 views)User (Old forums)MemberMay 9, 2007 at 3:30 amPost count: 23064
Thanks AndreC for the solution, but i got another solution yesterday by myself. In code i was making the same changes on the cell in the datasource associated to the grid and if i remove that code all works fine and everythings gets updated. In LeavingEdit i clear the grid to refresh changes but that is not needed anymore.
In this case the problem appeared editing one cell of the grid but i got the same error message when i refresh another grid in a timer event, with the only code to clear and update the grid, when no editing occurs, with the only user interaction of mouse cliks in grid rows. I suppose that the click event stays “unproccesed” by Windows when the timer event fires and when it clears the grid, the click event executes and found no rows in the grid.
Two things about your code. I don’t understand why i need to reasign the grid datasource in LeavingEdit event, and a question, selecting the current row in the Idle Event, as the process must wait until reaching that state, couldn’t be visually slow?
Many thanks for your help.
Imported from legacy forums. Posted by Javier (had 539 views)User (Old forums)MemberMay 9, 2007 at 3:38 pmPost count: 23064
Glad you resolve your issue.
As for reassigning the data source, this is just a sample code used to demonstrate what to do when the grid is reseted (and setting a new DataSource does a grid reset), it is not intended for you to do. I didn’t know what you were doing exactly in the event, so I just used this instead.
It is not a problem to execute this in the Idle event, it will not blink or anything.
Imported from legacy forums. Posted by André (had 3809 views)User (Old forums)MemberOctober 13, 2008 at 9:46 pmPost count: 23064
I realize this is a pretty old post, but I’m seeing a lot of applicability to some Grid work I’m currently working on. Two questions:
a.) Why does the grid have to wait for Application_Idle before updating the underlying dataSource? Is this a bug? Is there a fix in the works? I’ve noticed that no matter how simple or complex the grid I create, when LeavingEdit fires on a cell or row the first time, my DataSet.HasChanges is always false. If I then make another change, to another row or cell, then my DataSet shows as having changes. If this is truly databound, shouldn’t the update to the DataSet occur at the same point as changes are committed to the Grid?
b.) When I call DataSet.AcceptChanges, the entire grid refreshes, and it sets the row in focus back to the first row. Is there a way to a.) set this back to the row that was selected before the update or b.) if not, what is the best event to use to trap the row that was selected before the update (I’ll call it “LastFocusedRow” here)? Sometimes a user will commit a change by hitting Enter (which calls LeavingEdit…the LastFocusedRow will be the same as the one that was last edited). Other times the user will click to a different row, which I suppose could be captured by some other event, but that event would need to fire between LeavingEdit and Application_Idle…what event is that?
Imported from legacy forums. Posted by Rich (had 500 views)
- You must be logged in to reply to this topic.