Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. capturing the modifications in a datagrid

capturing the modifications in a datagrid

Scheduled Pinned Locked Moved C#
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samithas
    wrote on last edited by
    #1

    I want to check whether the content in a datagrid cell has been changed or not... how can u achieve this? samitha

    H 1 Reply Last reply
    0
    • S samithas

      I want to check whether the content in a datagrid cell has been changed or not... how can u achieve this? samitha

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      The cell itself doesn't record anything - the underlying data set does. If you're binding to a DataSet, DataTable, or DataView, get the DataRow for the row for that cell and query the DataRow.RowState property. There's several ways to do this. The easiest that takes sorting into account is like so:

      CurrencyManager cm = (CurrencyManager)
      dataGrid1.BindingContext[dataGrid1.DataSource,
      dataGrid1.DataMember];
      if (cm != null)
      {
      DataView view = (DataView)cm.List;
      DataRowView rowView = view.Item[dataGrid1.CurrentRowIndex];
      bool changed = rowView.Row.RowState == DataRowState.Modified;
      // Do something based on 'changed'
      }

      Microsoft MVP, Visual C# My Articles

      S 1 Reply Last reply
      0
      • H Heath Stewart

        The cell itself doesn't record anything - the underlying data set does. If you're binding to a DataSet, DataTable, or DataView, get the DataRow for the row for that cell and query the DataRow.RowState property. There's several ways to do this. The easiest that takes sorting into account is like so:

        CurrencyManager cm = (CurrencyManager)
        dataGrid1.BindingContext[dataGrid1.DataSource,
        dataGrid1.DataMember];
        if (cm != null)
        {
        DataView view = (DataView)cm.List;
        DataRowView rowView = view.Item[dataGrid1.CurrentRowIndex];
        bool changed = rowView.Row.RowState == DataRowState.Modified;
        // Do something based on 'changed'
        }

        Microsoft MVP, Visual C# My Articles

        S Offline
        S Offline
        samithas
        wrote on last edited by
        #3

        thnks 4 the reply...My actual requiremnt is this.. Suppiose u have a datagrid with only one row has been entred. When you click on the close button on the form(without giving the focus on any other control) it should check whether the row has a value. This ckeck happens correctly when u click else where on the form or on the next row and then try to close.. can anybody help me...? samitha

        H 1 Reply Last reply
        0
        • S samithas

          thnks 4 the reply...My actual requiremnt is this.. Suppiose u have a datagrid with only one row has been entred. When you click on the close button on the form(without giving the focus on any other control) it should check whether the row has a value. This ckeck happens correctly when u click else where on the form or on the next row and then try to close.. can anybody help me...? samitha

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Please state your actual requirement next time. It will save time. You should still get the currency manager like I showed you in the first reply in your Form.Closing event handler. Then you can call CurrencyManager.EndCurrentEdit. See the method documentation for CurrencyManager.EndCurrentEdit for an example. You could also use DataGrid.EndEdit, which also includes an example of usage in the method documentation in the .NET Framework SDK.

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups