DataGrid: Update data source when editing a cell and closing the f

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TT (Tom Tempelaere)

    DataGrid: Update data source when editing a cell and closing the f

    Hi,

    Suppose there is a DataGrid on a form bound to a DataTable. When a user is
    editing a cell without leaving the cell, and then closes the form, the value
    is not updated to the underlying data source.

    How can I accomplish this?

    Thanks,
    --
    Tom Tempelaere.
  • Dmytro Lapshyn [MVP]

    #2
    Re: DataGrid: Update data source when editing a cell and closing the f

    CurrencyManager cm =
    (CurrencyManage r)this.BindingC ontext[dataGrid.DataSo urce,
    dataGrid.DataMe mber];
    cm.EndCurrentEd it();
    DataGridColumnS tyle curColumn =
    dataGrid.TableS tyles[0].GridColumnStyl es[dataGrid.Curren tCell.ColumnNum ber];
    dataGrid.EndEdi t(curColumn, dataGrid.Curren tRowIndex, false);

    --
    Sincerely,
    Dmytro Lapshyn [Visual Developer - Visual C# MVP]


    "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThot mailD.Tcom|/\|@P$0_|\|_>
    wrote in message news:5E9518AE-E0B2-4B81-974B-7CD6808DE62A@mi crosoft.com...[color=blue]
    > Hi,
    >
    > Suppose there is a DataGrid on a form bound to a DataTable. When a user is
    > editing a cell without leaving the cell, and then closes the form, the
    > value
    > is not updated to the underlying data source.
    >
    > How can I accomplish this?
    >
    > Thanks,
    > --
    > Tom Tempelaere.[/color]

    Comment

    • TT (Tom Tempelaere)

      #3
      Re: DataGrid: Update data source when editing a cell and closing t

      It doesn't work. EndEdit *always* returns false, even if the entry is valid.

      Unbelievable that even such trivial operations are so hard to find, and when
      you try them they don't even work.

      Duh,
      Tom T.

      "Dmytro Lapshyn [MVP]" wrote:
      [color=blue]
      > CurrencyManager cm =
      > (CurrencyManage r)this.BindingC ontext[dataGrid.DataSo urce,
      > dataGrid.DataMe mber];
      > cm.EndCurrentEd it();
      > DataGridColumnS tyle curColumn =
      > dataGrid.TableS tyles[0].GridColumnStyl es[dataGrid.Curren tCell.ColumnNum ber];
      > dataGrid.EndEdi t(curColumn, dataGrid.Curren tRowIndex, false);
      >
      > --
      > Sincerely,
      > Dmytro Lapshyn [Visual Developer - Visual C# MVP]
      >
      >
      > "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThot mailD.Tcom|/\|@P$0_|\|_>
      > wrote in message news:5E9518AE-E0B2-4B81-974B-7CD6808DE62A@mi crosoft.com...[color=green]
      > > Hi,
      > >
      > > Suppose there is a DataGrid on a form bound to a DataTable. When a user is
      > > editing a cell without leaving the cell, and then closes the form, the
      > > value
      > > is not updated to the underlying data source.
      > >
      > > How can I accomplish this?
      > >
      > > Thanks,
      > > --
      > > Tom Tempelaere.[/color]
      >
      >[/color]

      Comment

      • Dmytro Lapshyn [MVP]

        #4
        Re: DataGrid: Update data source when editing a cell and closing t

        Try to swap the order - call EndEdit first and then EndCurrentEdit on the
        CurrencyManager .

        --
        Sincerely,
        Dmytro Lapshyn [Visual Developer - Visual C# MVP]


        "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThot mailD.Tcom|/\|@P$0_|\|_>
        wrote in message news:8D9FD09B-B41E-4EF2-B42C-204D428A43C3@mi crosoft.com...[color=blue]
        > It doesn't work. EndEdit *always* returns false, even if the entry is
        > valid.
        >
        > Unbelievable that even such trivial operations are so hard to find, and
        > when
        > you try them they don't even work.
        >
        > Duh,
        > Tom T.
        >
        > "Dmytro Lapshyn [MVP]" wrote:
        >[color=green]
        >> CurrencyManager cm =
        >> (CurrencyManage r)this.BindingC ontext[dataGrid.DataSo urce,
        >> dataGrid.DataMe mber];
        >> cm.EndCurrentEd it();
        >> DataGridColumnS tyle curColumn =
        >> dataGrid.TableS tyles[0].GridColumnStyl es[dataGrid.Curren tCell.ColumnNum ber];
        >> dataGrid.EndEdi t(curColumn, dataGrid.Curren tRowIndex, false);
        >>
        >> --
        >> Sincerely,
        >> Dmytro Lapshyn [Visual Developer - Visual C# MVP]
        >>
        >>
        >> "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThot mailD.Tcom|/\|@P$0_|\|_>
        >> wrote in message
        >> news:5E9518AE-E0B2-4B81-974B-7CD6808DE62A@mi crosoft.com...[color=darkred]
        >> > Hi,
        >> >
        >> > Suppose there is a DataGrid on a form bound to a DataTable. When a user
        >> > is
        >> > editing a cell without leaving the cell, and then closes the form, the
        >> > value
        >> > is not updated to the underlying data source.
        >> >
        >> > How can I accomplish this?
        >> >
        >> > Thanks,
        >> > --
        >> > Tom Tempelaere.[/color]
        >>
        >>[/color][/color]

        Comment

        • TT \(Tom Tempelaere\)

          #5
          Re: DataGrid: Update data source when editing a cell and closing t

          Dmytro,

          Thanks for the suggestion. I'll try it out.

          Thank you,
          Tom T.
          PS: Sorry for the frustrated tone ;-), DataGrid is rather complex sometimes.

          "Dmytro Lapshyn [MVP]" <x-code@no-spam-please.hotpop.c om> schreef in bericht
          news:%23W3hJB1R FHA.2664@TK2MSF TNGP15.phx.gbl. ..[color=blue]
          > Try to swap the order - call EndEdit first and then EndCurrentEdit on the
          > CurrencyManager .
          >
          > --
          > Sincerely,
          > Dmytro Lapshyn [Visual Developer - Visual C# MVP]
          >
          >
          > "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThot mailD.Tcom|/\|@P$0_|\|_>
          > wrote in message
          > news:8D9FD09B-B41E-4EF2-B42C-204D428A43C3@mi crosoft.com...[color=green]
          >> It doesn't work. EndEdit *always* returns false, even if the entry is
          >> valid.
          >>
          >> Unbelievable that even such trivial operations are so hard to find, and
          >> when
          >> you try them they don't even work.
          >>
          >> Duh,
          >> Tom T.
          >>
          >> "Dmytro Lapshyn [MVP]" wrote:
          >>[color=darkred]
          >>> CurrencyManager cm =
          >>> (CurrencyManage r)this.BindingC ontext[dataGrid.DataSo urce,
          >>> dataGrid.DataMe mber];
          >>> cm.EndCurrentEd it();
          >>> DataGridColumnS tyle curColumn =
          >>> dataGrid.TableS tyles[0].GridColumnStyl es[dataGrid.Curren tCell.ColumnNum ber];
          >>> dataGrid.EndEdi t(curColumn, dataGrid.Curren tRowIndex, false);
          >>>
          >>> --
          >>> Sincerely,
          >>> Dmytro Lapshyn [Visual Developer - Visual C# MVP]
          >>>
          >>>
          >>> "TT (Tom Tempelaere)"
          >>> <_|\|_0$P@|/\|titi____AThot mailD.Tcom|/\|@P$0_|\|_>
          >>> wrote in message
          >>> news:5E9518AE-E0B2-4B81-974B-7CD6808DE62A@mi crosoft.com...
          >>> > Hi,
          >>> >
          >>> > Suppose there is a DataGrid on a form bound to a DataTable. When a
          >>> > user is
          >>> > editing a cell without leaving the cell, and then closes the form, the
          >>> > value
          >>> > is not updated to the underlying data source.
          >>> >
          >>> > How can I accomplish this?
          >>> >
          >>> > Thanks,
          >>> > --
          >>> > Tom Tempelaere.
          >>>
          >>>[/color][/color]
          >[/color]


          Comment

          Working...