detecting changes in a datagridview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    #1

    detecting changes in a datagridview

    As your probably aware the datagridview doesn't update it's source
    datatable with changes to a cell until you move off that cell. Suppose
    somone makes a change in a cell of my datagridview then clicks to go
    elsewhere in the program--how can I be assured that change is
    transmitted back to the source datatable?
  • Jack Jackson

    #2
    Re: detecting changes in a datagridview

    On Wed, 05 Dec 2007 16:12:03 -0500, cj <cj@nospam.nosp amwrote:
    >As your probably aware the datagridview doesn't update it's source
    >datatable with changes to a cell until you move off that cell. Suppose
    >somone makes a change in a cell of my datagridview then clicks to go
    >elsewhere in the program--how can I be assured that change is
    >transmitted back to the source datatable?
    One possibility is to force the changes to be made immediately,
    although that won't work usefully if you have validation on the cell.

    There is a lot of info about DataGridView here:
    <http://www.windowsclie nt.net/Samples/Go%20To%20Marke t/DataGridView/DataGridView%20 FAQ.doc>

    Section 3.2 describes the process for a checkbox column, and there is
    a code snippet here
    <http://207.46.236.188/MSDN/ShowPost.aspx?P ostID=2105950&S iteID=1>

    Googling for CurrentCellDirt yStateChanged has a number of hits, many
    of which are not working at the moment but they may work later.

    There is also some information here:
    <http://www.msdner.com/dev-archive/106/2-7-1062147.shtm>

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: detecting changes in a datagridview

      cj,

      Call the EndEdit on the datasource.

      Cor
      As your probably aware the datagridview doesn't update it's source
      datatable with changes to a cell until you move off that cell. Suppose
      somone makes a change in a cell of my datagridview then clicks to go
      elsewhere in the program--how can I be assured that change is
      transmitted back to the source datatable?

      Comment

      • Linda Liu[MSFT]

        #4
        RE: detecting changes in a datagridview

        Hi Chris,

        When we select and type in the current cell in a DataGridView, the editing
        control attached to the current cell is shown and the current cell is in
        edit mode. If you click on another form in the application, only one event
        is fired, i.e. the current editing control's LostFocus event.

        So we could subscribe this event to get notified when the user clicks to go
        elsewhere in the application so as to apply the changes in the current cell
        back to the underlying data source.

        The following is a sample to do this:

        Private Sub DataGridView1_C ellValidated(By Val sender As Object, ByVal e As
        System.Windows. Forms.DataGridV iewCellEventArg s) Handles
        DataGridView1.C ellValidated
        If (Me.DataGridVie w1.EditingContr ol IsNot Nothing) Then
        RemoveHandler DataGridView1.E ditingControl.L ostFocus, AddressOf
        Control_LostFoc us
        End If
        End Sub

        Private Sub DataGridView1_E ditingControlSh owing(ByVal sender As Object,
        ByVal e As System.Windows. Forms.DataGridV iewEditingContr olShowingEventA rgs)
        Handles DataGridView1.E ditingControlSh owing
        AddHandler e.Control.LostF ocus, AddressOf Control_LostFoc us
        End Sub

        Sub Control_LostFoc us(ByVal sender As Object, ByVal e As EventArgs)
        If (Me.DataGridVie w1.IsCurrentCel lInEditMode) Then
        RemoveHandler Me.DataGridView 1.EditingContro l.LostFocus,
        AddressOf Control_LostFoc us
        Me.DataGridView 1.EndEdit()
        End If
        End Sub

        Hope this helps.
        If you have any question, please feel free to let me know.

        Sincerely,
        Linda Liu
        Microsoft Online Community Support

        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        http://msdn.microsoft.com/subscripti...ult.aspx#notif
        ications.

        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/subscripti...t/default.aspx.
        =============== =============== =============== =====

        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • cj

          #5
          Re: detecting changes in a datagridview

          Thanks, but right now all that is information overload. Folks here are
          aware you can build a UI in 10 minutes. What they don't understand is
          what another user put so clearly on another forum "10 minutes to put a
          UI on a database table, 3 hours messing around trying to get it to work
          correctly." I don't have time to read all that. Thankfully my
          tinkering and these questions is helping.

          Jack Jackson wrote:
          On Wed, 05 Dec 2007 16:12:03 -0500, cj <cj@nospam.nosp amwrote:
          >
          >As your probably aware the datagridview doesn't update it's source
          >datatable with changes to a cell until you move off that cell. Suppose
          >somone makes a change in a cell of my datagridview then clicks to go
          >elsewhere in the program--how can I be assured that change is
          >transmitted back to the source datatable?
          >
          One possibility is to force the changes to be made immediately,
          although that won't work usefully if you have validation on the cell.
          >
          There is a lot of info about DataGridView here:
          <http://www.windowsclie nt.net/Samples/Go%20To%20Marke t/DataGridView/DataGridView%20 FAQ.doc>
          >
          Section 3.2 describes the process for a checkbox column, and there is
          a code snippet here
          <http://207.46.236.188/MSDN/ShowPost.aspx?P ostID=2105950&S iteID=1>
          >
          Googling for CurrentCellDirt yStateChanged has a number of hits, many
          of which are not working at the moment but they may work later.
          >
          There is also some information here:
          <http://www.msdner.com/dev-archive/106/2-7-1062147.shtm>

          Comment

          • cj

            #6
            Re: detecting changes in a datagridview

            Yes, I find that does work but due to other situations in the code it
            wasn't immediately apparent. I think with some rearranging it will do.

            Cor Ligthert[MVP] wrote:
            cj,
            >
            Call the EndEdit on the datasource.
            >
            Cor
            >
            >As your probably aware the datagridview doesn't update it's source
            >datatable with changes to a cell until you move off that cell.
            >Suppose somone makes a change in a cell of my datagridview then clicks
            >to go elsewhere in the program--how can I be assured that change is
            >transmitted back to the source datatable?

            Comment

            • cj

              #7
              Re: detecting changes in a datagridview

              Linda, sorry this pretty much goes over my head. Cor and some playing
              around on my part have been able to make this a non-issue now. Thanks
              anyway.

              Linda Liu[MSFT] wrote:
              Hi Chris,
              >
              When we select and type in the current cell in a DataGridView, the editing
              control attached to the current cell is shown and the current cell is in
              edit mode. If you click on another form in the application, only one event
              is fired, i.e. the current editing control's LostFocus event.
              >
              So we could subscribe this event to get notified when the user clicks to go
              elsewhere in the application so as to apply the changes in the current cell
              back to the underlying data source.
              >
              The following is a sample to do this:
              >
              Private Sub DataGridView1_C ellValidated(By Val sender As Object, ByVal e As
              System.Windows. Forms.DataGridV iewCellEventArg s) Handles
              DataGridView1.C ellValidated
              If (Me.DataGridVie w1.EditingContr ol IsNot Nothing) Then
              RemoveHandler DataGridView1.E ditingControl.L ostFocus, AddressOf
              Control_LostFoc us
              End If
              End Sub
              >
              Private Sub DataGridView1_E ditingControlSh owing(ByVal sender As Object,
              ByVal e As System.Windows. Forms.DataGridV iewEditingContr olShowingEventA rgs)
              Handles DataGridView1.E ditingControlSh owing
              AddHandler e.Control.LostF ocus, AddressOf Control_LostFoc us
              End Sub
              >
              Sub Control_LostFoc us(ByVal sender As Object, ByVal e As EventArgs)
              If (Me.DataGridVie w1.IsCurrentCel lInEditMode) Then
              RemoveHandler Me.DataGridView 1.EditingContro l.LostFocus,
              AddressOf Control_LostFoc us
              Me.DataGridView 1.EndEdit()
              End If
              End Sub
              >
              Hope this helps.
              If you have any question, please feel free to let me know.
              >
              Sincerely,
              Linda Liu
              Microsoft Online Community Support
              >
              =============== =============== =============== =====
              Get notification to my posts through email? Please refer to
              http://msdn.microsoft.com/subscripti...ult.aspx#notif
              ications.
              >
              Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
              where an initial response from the community or a Microsoft Support
              Engineer within 1 business day is acceptable. Please note that each follow
              up response may take approximately 2 business days as the support
              professional working with you may need further investigation to reach the
              most efficient resolution. The offering is not appropriate for situations
              that require urgent, real-time or phone-based interactions or complex
              project analysis and dump analysis issues. Issues of this nature are best
              handled working with a dedicated Microsoft Support Engineer by contacting
              Microsoft Customer Support Services (CSS) at
              http://msdn.microsoft.com/subscripti...t/default.aspx.
              =============== =============== =============== =====
              >
              This posting is provided "AS IS" with no warranties, and confers no rights.
              >

              Comment

              • Cor Ligthert[MVP]

                #8
                Re: detecting changes in a datagridview

                Linda,

                AFAIK does the push of a button not fire the lostfocus event. Armin can much
                better tell this then me, however this has been forever with Microsoft
                controls.

                Cor

                Comment

                Working...