Home Forums WinForms controls Xceed Grid for WinForms An attempt was made to select a row that does not belong…

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15233 |

    I have a grid which I must refresh frequently. In this case, I clear the rows and rebuild it from scratch.

    Everythings works except if I click in the grid while refreshing, I’ve got this error. (To reproduce the error, you need to click a lot … maybe to get the good moment, maybe that the click message is queued and processed in wrong time …)

    Do you know a workaround, will it be fixed in a later version (I am using version 3.5)

    Thanks.

    ——————-
    {“An attempt was made to select a row that does not belong to a grid.”}
    at Xceed.Grid.Row.SetSelected(Boolean isSelected)
    at Xceed.Grid.Collections.SelectedRowList.ResetTo(Row row)
    at Xceed.Grid.GridControl.DoRowSelections(Row oldCurrentRow, Row newCurrentRow, Keys modifierKeys, Boolean rowChangedWithMouse)
    at Xceed.Grid.MasterGrid.SelectWithMouse(VisualGridElement gridElement, MouseButtons button, Point mousePosition, Boolean allowCellEdition)
    at Xceed.Grid.Cell.OnMouseDown(MouseEventArgs e)
    at Xceed.Grid.GridControl.DoMouseDown(MouseEventArgs e)
    at Xceed.Grid.GridControl.OnMouseDown(MouseEventArgs e)
    at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at Xceed.Grid.GridControl.WndProc(Message& m)
    at Reflection.UI.ExtendedGridControl.WndProc(Message& m) in X:\pipeline-onyx\Dev\NewReflection\Source\Tools\Mosaic\Reflection\Reflection.UI\Project\Source\PropertyGrid\ExtendedGridControl.cs:line 50

    Imported from legacy forums. Posted by Jonathan (had 7401 views)

    User (Old forums)
    Member
    Post count: 23064

    This is not a bug. What happens is that a row is selected at MouseDown, then the refresh code executes, which recreates all the rows, then the grid tries to reposition itself to the row it got at MouseDown, but this row does not exist anymore.

    It is important not to reset the grid at that moment. A possible solution would be to subscribe to the Application.Idle event when your are ready to refresh the grid, then in the event handler unsubscribe to the Idle event, and execute the refresh code right way.

    Imported from legacy forums. Posted by André (had 500 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your reply.

    -For the moment I resolved the exception by catching it in the WndProc and ignoring it (not a beautiful fix but it works).

    -I will consider your solution

    Imported from legacy forums. Posted by Jonathan (had 746 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi jontdelorme,

    I have the same problem in a grid that refreshes with a timer an also in a grid that doesn’t change its rows.

    Please, can you explain me how to catch WndProc and ignore the click event, or, better, can you give me the code to do it?.

    You can answer by replying this post.

    Many thanks.

    Imported from legacy forums. Posted by Javier (had 3968 views)

    User (Old forums)
    Member
    Post count: 23064

    I am also struggling with this exception.  It is beyond me why you would trow such an exception for such a simple error.  I cant seem to be able to trap it.  My application starts from a Sub Main and I have Try Catch clauses around all of my code and this exception gets thrown all the way up to the Sub Main exception handler.  there are several instances where the Grid is throwing exceptions like this and it is starting to hamper development.

    For my case because of auditing requirements every cell edit must be saved immediately to the database.  So I handle the EditLeft event, call my SP, the return of which is a n new data set, each edit may impact several rows and columns so we have to get a new data set back.  Well, all works well until the user clicks off of the current row to another row to commit the data.  This throws the exception noted above since it is trying to set the selected row to the one the user selected but since I had to unbind and rebind the data set it no longer exists.

    I would respectfully request that Xceed reconsider throwing such exceptions in a manner that we can not catch.  Or provide a way to turn off such exceptions when we need to. I mean is it really that huge of an issue if the grid can not reselect the row?  Why not just raise an event that we can handle and let us decide what is an application terminating event.

    I have come to rely on the flexibility of the Xceed grid, but exceptions like this and the exception that is thrown when I cancel an edit of a cell through code is starting to be a real issue for us.

    What can I do to resolve this?

    I am currently using the Application.Idle event but I do not like the fact that I really don’t know when that event will fire, I know it is almost immediate but it is not a deterministic as I need for this application.

    Thanks

     

    Brian

     

    Imported from legacy forums. Posted by Brian (had 3565 views)

    User (Old forums)
    Member
    Post count: 23064

    In fact, this type of exception should be caught by the gird, so it should not be thrown all the way to the application.

    We have filled a bug report for this, and will be correcting this in a future release, though we can’t provide a time frame at this point.

     

    Imported from legacy forums. Posted by André (had 3262 views)

    User (Old forums)
    Member
    Post count: 23064

    We also have the same exception, from times to times (using the latest package – 3.2.9257.09160).  The problem only occur when manual modification are made.  Here a part of our code :

    with myGrid

                 With .Columns(“unite”)
                    .VisibleIndex = oprIncrAft(vIndex)
                    .Title = “Qté.”
                    .Width = 45
                End With
                AddHandler .DataRowTemplate.Cells(“unite”).ValueChanged, AddressOf showTotal

                With .Columns(“prix_unitaire”)
                    .VisibleIndex = oprIncrAft(vIndex)
                    .Title = “$ unité”
                    .Width = 60
                    .FormatSpecifier = “c”
                End With
                AddHandler .DataRowTemplate.Cells(“prix_unitaire”).ValueChanged, AddressOf showTotal

                .Columns.Add(New Xceed.Grid.Column(“sous-total”, GetType(Single)))
                With .Columns(“sous-total”)
                    .VisibleIndex = oprIncrAft(vIndex)
                    .CellViewerManager = New Xceed.Grid.Viewers.NumericViewer
                    .Title = “Sous-Total”
                    .ReadOnly = True
                    .Width = 75
                    .FormatSpecifier = “c”
                End With

    end with

        Private Sub showTotal(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Try
                Dim cell As Xceed.Grid.DataCell = CType(sender, Xceed.Grid.DataCell)
                Dim DR As Xceed.Grid.DataRow = cell.ParentRow

                Dim qte As Double = coalesce(DR.Cells(“unite”).Value, 0)
                Dim prix As Double = coalesce(DR.Cells(“prix_unitaire”).Value, 0)
                DR.Cells(“sous-total”).Value = CSng(Math.Round(qte * prix, 2))

                If (cell.IsBeingEdited) Then showGrandTotal()
            Catch ex As Exception
                ErrorManagement(Name, “showTotal”, ex.Message)
            End Try
        End Sub

        Private Sub showGrandTotal()
            Dim sousTotal As Double = 0
            Dim tps As Double = 0
            Dim tvq As Double = 0
            Dim total As Double = 0

            Try
                For t = 0 To Depenses_detailBindingSource.Count – 1
                    Dim qte As Double = coalesce(Depenses_detailBindingSource(t)!unite, 0)
                    Dim prix As Double = coalesce(Depenses_detailBindingSource(t)!prix_unitaire, 0)

                    Dim sousTotalTemp As Double
                    Dim tpsTemp As Double = 0
                    Dim tvqTemp As Double = 0

                    sousTotalTemp = Math.Round(qte * prix, 2)
                    sousTotalTemp = Math.Round(sousTotalTemp * CDbl(txtTauxChange.Text), 2)

                    sousTotal += sousTotalTemp
                    tps += tpsTemp
                    tvq += tvqTemp
                    total += sousTotalTemp + tpsTemp + tvqTemp
                Next

                txtSousTotal.Text = FormatCurrency(sousTotal)
                txtTPS.Text = FormatCurrency(tps)
                txtTVQ.Text = FormatCurrency(tvq)
                txtTotal.Text = FormatCurrency(total)
            Catch ex As Exception
                ErrorManagement(Name, “showGrandTotal”, ex.Message)
            End Try
        End Sub

    Imported from legacy forums. Posted by Daniel (had 2449 views)

    User (Old forums)
    Member
    Post count: 23064

    Some exceptions are managed by the grid itself.  Sometimes, the grid can’t handle the exception and it cascades to a higher level. 

    To be able to see all exceptions that the grid could be trying to manage, do the following:  (if you are using Visual Studio 2008), you should *UNCHECK* Tools -> Options -> Debugging -> Enable Just My Code and you should *CHECK* Debug -> Exceptions -> Common Language Runtime Exceptions Thrown [ ] This will allow you to see what exception is thrown and why.

    From this point, you should be able to trap the exceptions that you could not without these settings.

    Once that the code has been revised and corrected, it is recommended to *UNCHECK* Debug -> Exceptions -> Common Language Runtime Exceptions Thrown [ ] or otherwise, you are at risk of seeing exceptions that you don’t want to see.  ( http://xceed.com/CS/forums/thread/2983.aspx and http://xceed.com/CS/forums/thread/21522.aspx )

    Imported from legacy forums. Posted by Ghislain (had 2241 views)

    User (Old forums)
    Member
    Post count: 23064

    I find what causing the grid to freak.

    In one specific case, I manually update a field which is not shown.  “myBindingSource.current(“my_field”) = myNewValue”.

    I have multiple table in my dataSet.  The main table and some sub-tables.  The xceed grid is used to display data in sub-tables.  The value I’m updating is on the main table (which the grid doesn’t do anything with it).  And the bug only occur if the save method is called and then the user made a modification in a cell and then the event valueChanged of the cell call the line above.

    The fixe I used is to use a binded text field.

    Imported from legacy forums. Posted by Daniel (had 3315 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.