Home All Groups Group Topic Archive Search About

Editing Multiple DataGridViews

Author
20 Apr 2006 1:59 PM
jpenn44
I have multiple datagridviews on one form.  I am allowing editing in the grid, and am performing error checking.

I am validating the data, if it isn't valid, I am cancelling any other events fired.  My problem is, I am validating in grid A, if they click in Grid B, I am popping up a message box informing them of the error, but if they click ok on the message box, and then click in grid B again, it goes on.  The following is a code snippet:


If Not SpecialPricingIsValid() Then
With grdvMagSpecialPricing
.ClearSelection()
.CurrentCell=                                          grdvMagSpecialPricing.CurrentRow.Cells(SetInvalidColumnNumber)
.Focus()
End With
e.Cancel = True
Exit Sub
End If

I'm not real sure how to bring the focus back to the grid with the error.  I'm setting the currentcell, and setting focus, I would thing that would do it.

Any help would be appreciated. -- jpenn44 ------------------------------------------------------------------------ jpenn44's Profile: http://www.hightechtalks.com/m322 View this thread: http://www.hightechtalks.com/t365040

Author
20 Apr 2006 6:11 PM
Ken Tucker [MVP]
Hi,

       Why do you have 2 grids bound to the same data on one form.  The
datagridview has a cellvalidating event that you get the old value in the
cell as well as the new value.
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/38b61e6e5c8e87d4/147b8aa55ed5fd23?q=datagridview+tucker&rnum=9#147b8aa55ed5fd23

Ken
-----------------------

Show quoteHide quote
"jpenn44" wrote:

>
> I have multiple datagridviews on one form.  I am allowing editing in the
> grid, and am performing error checking.
>
> I am validating the data, if it isn't valid, I am cancelling any other
> events fired.  My problem is, I am validating in grid A, if they click
> in Grid B, I am popping up a message box informing them of the error,
> but if they click ok on the message box, and then click in grid B
> again, it goes on.  The following is a code snippet:
>
>
> If Not SpecialPricingIsValid() Then
> With grdvMagSpecialPricing
> .ClearSelection()
> .CurrentCell=                                         
>
> grdvMagSpecialPricing.CurrentRow.Cells(SetInvalidColumnNumber)
> .Focus()
> End With
> e.Cancel = True
> Exit Sub
> End If
>
> I'm not real sure how to bring the focus back to the grid with the
> error.  I'm setting the currentcell, and setting focus, I would thing
> that would do it.
>
> Any help would be appreciated.
>
>
> --
> jpenn44
> ------------------------------------------------------------------------
> jpenn44's Profile: http://www.hightechtalks.com/m322
> View this thread: http://www.hightechtalks.com/t365040
>
>
Author
21 Apr 2006 5:46 PM
jpenn44
I don't have two grids bound to the same data, they are each bound to a
unique dataset, although I don't see the relevance of that.

I am using the cellvalidating event....the code is within that, to
validate the data....

But I am trying to capture when the user enters invalid data, to set
the focus back to the invalid cell, no matter where they click.  I can
do this if they click in the datagridview where they are editing the
row.  But whenever they click outside that grid, I can still display
the error message, but cannot set the focus back to the edited cell.



'Ken Tucker [MVP Wrote:
Show quoteHide quote
> ']Hi,
>
> Why do you have 2 grids bound to the same data on one form.  The
> datagridview has a cellvalidating event that you get the old value in
> the
> cell as well as the new value.
>
> http://tinyurl.com/ofb88
>
> Ken
> -----------------------
>
> "jpenn44" wrote:


--
jpenn44
------------------------------------------------------------------------
jpenn44's Profile: http://www.hightechtalks.com/m322
View this thread: http://www.hightechtalks.com/t365040