adding empty row to databound datagrid

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

    #1

    adding empty row to databound datagrid

    In my Win App, I have a datagrid that's bound to a dataset. When the form
    loads, the datagrid fills. How can I add an empty row to the end of the
    datagrid during a button click (similar to pressing Tab when mouse pointer
    is on last field of last record of datagrid)? The datagrid's read-only so
    the user won't be able to modify it unless he wants to add a new record via
    the datagrid (by adding the empty row).
    Also, if I modify the datagrid, how can I update the physical data? I only
    have the dataset to

    Thanks.



  • William Ryan

    #2
    Re: adding empty row to databound datagrid

    You can add a new DataRow to the DataTable, you can use a bindingContext or
    BindingManagerB ase and use the .AddNew() method. Is the grid supposed to be
    read-only for everything but new Rows? I'm not sure if I'm understanding
    correctly.

    As far as updating goes, do you mean the Data in the DataBase? Since it's a
    WinApp, I'm assuming your grid is bound to a DataTable. Any changes made
    through the grid will be reflected in the DataTable. So you can simply call
    DataAdapter.Upd ate(yourTable) and provided you have update Logic , that's
    all you should need. If you havne't used a DataAdapter Configuration
    Wizard, you'll need to either use a CommandBuilder or roll out your own
    stuff.
    Either way, it's pretty straightforward . I'm not sure I understand the
    problem, but if you can give me a little more detail, I can probably get you
    through it.

    Cheers,

    Bill
    "Jim" <NA> wrote in message news:ee7uM%237d DHA.3676@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > In my Win App, I have a datagrid that's bound to a dataset. When the form
    > loads, the datagrid fills. How can I add an empty row to the end of the
    > datagrid during a button click (similar to pressing Tab when mouse pointer
    > is on last field of last record of datagrid)? The datagrid's read-only so
    > the user won't be able to modify it unless he wants to add a new record[/color]
    via[color=blue]
    > the datagrid (by adding the empty row).
    > Also, if I modify the datagrid, how can I update the physical data? I only
    > have the dataset to
    >
    > Thanks.
    >
    >
    >[/color]


    Comment

    • Jim

      #3
      Re: adding empty row to databound datagrid

      Thanks for your reply. Sorry for the incomplete post.
      The datagrid is read-only because I use it to display data. But if the user
      wants to add another record to the grid, he'll click the Add button and a
      new empty row will appear in the DG for him/her to add the new record
      As for updating, I only have the dataset because that's what the method
      returns. I'd like to be able to go through the whole datagrid to see what
      has been added.
      Thanks.

      "William Ryan" <dotnetguru@com cast.nospam.net > wrote in message
      news:eQbmMD8dDH A.3992@TK2MSFTN GP11.phx.gbl...[color=blue]
      > You can add a new DataRow to the DataTable, you can use a bindingContext[/color]
      or[color=blue]
      > BindingManagerB ase and use the .AddNew() method. Is the grid supposed to[/color]
      be[color=blue]
      > read-only for everything but new Rows? I'm not sure if I'm understanding
      > correctly.
      >
      > As far as updating goes, do you mean the Data in the DataBase? Since it's[/color]
      a[color=blue]
      > WinApp, I'm assuming your grid is bound to a DataTable. Any changes made
      > through the grid will be reflected in the DataTable. So you can simply[/color]
      call[color=blue]
      > DataAdapter.Upd ate(yourTable) and provided you have update Logic , that's
      > all you should need. If you havne't used a DataAdapter Configuration
      > Wizard, you'll need to either use a CommandBuilder or roll out your own
      > stuff.
      > Either way, it's pretty straightforward . I'm not sure I understand the
      > problem, but if you can give me a little more detail, I can probably get[/color]
      you[color=blue]
      > through it.
      >
      > Cheers,
      >
      > Bill
      > "Jim" <NA> wrote in message[/color]
      news:ee7uM%237d DHA.3676@TK2MSF TNGP09.phx.gbl. ..[color=blue][color=green]
      > > In my Win App, I have a datagrid that's bound to a dataset. When the[/color][/color]
      form[color=blue][color=green]
      > > loads, the datagrid fills. How can I add an empty row to the end of the
      > > datagrid during a button click (similar to pressing Tab when mouse[/color][/color]
      pointer[color=blue][color=green]
      > > is on last field of last record of datagrid)? The datagrid's read-only[/color][/color]
      so[color=blue][color=green]
      > > the user won't be able to modify it unless he wants to add a new record[/color]
      > via[color=green]
      > > the datagrid (by adding the empty row).
      > > Also, if I modify the datagrid, how can I update the physical data? I[/color][/color]
      only[color=blue][color=green]
      > > have the dataset to
      > >
      > > Thanks.
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...