none
entity binding to datagridview could not refresh and display new data just added

    Question

  • i create an EF3 model with "filter" defined object, and i bind the entity data to the winform datagridview through a "filterbindingsource" , it works. but when i add new data to the entity with the code below ,the datagrid will not display the new data except i restart the program . how can i refresh the EF data to the datagridview after adding new data?

    "add new"  button onclick code:

      filter filter = new filter();
      filter.uid = System.Guid.NewGuid().ToString();
      filter.name = "guid.newguid";
      filter.memo = "guid.newguid";
      form_entity.AddTofilter(filter);
          
      form_entity.SaveChanges();
      filterBindingSource.DataSource = form_entity.filter;
      this.Refresh();


    Sunday, July 17, 2011 12:27 PM

Answers

  • On 7/17/2011 1:36 PM, lin lewis wrote:
    >
    > i 'd try these code , but useless
    >
    > filterBindingSource.CurrencyManager.Refresh();
    > this.dataGridView1.DataSource = null;
    > this.dataGridView1.DataSource = this.filterBindingSource;
    > this.dataGridView1.Refresh();
    >
    > at last , i rebind the bindingsource and make it , but seems not to be
    > the best.
    >
    > filterBindingSource.DataSource = null;
    > filterBindingSource.DataSource = form_entity.filter;
    >
    > how can i solve the problem on the right way ?
    >
     
    Well, I think you should be reading the data on a round-trip back to the
    database and loading the control based on you going back to read the
    added data from the database.
     
    Tuesday, July 19, 2011 2:25 AM

All replies

  • On 7/17/2011 8:27 AM, lin lewis wrote:
    > i create an EF3 model with "filter" defined object, and i bind the
    > entity data to the winform datagridview through a "filterbindingsource"
    > , it works. but when i add new data to the entity with the code below
    > ,the datagrid will not display the new data except i restart the program
    > . how can i refresh the EF data to the datagridview after adding new data?
    >
    > "add new" button onclick code:
    >
    > filter filter = new filter();
    > filter.uid = System.Guid.NewGuid().ToString();
    > filter.name = "guid.newguid";
    > filter.memo = "guid.newguid";
    > form_entity.AddTofilter(filter);
    >
    > form_entity.SaveChanges();
    > filterBindingSource.DataSource = form_entity.filter;
    > this.Refresh();
    >
    >
     
    I think you are going to have to repopulate the grid with a call to the
    database to get new data.
     
    Sunday, July 17, 2011 12:57 PM

  •                 i 'd  try these code , but useless

                    filterBindingSource.CurrencyManager.Refresh();
                    this.dataGridView1.DataSource = null;
                    this.dataGridView1.DataSource = this.filterBindingSource;
                    this.dataGridView1.Refresh();

                  at last , i rebind the bindingsource and make it , but  seems not to be the best.

                    filterBindingSource.DataSource = null;
                    filterBindingSource.DataSource = form_entity.filter;
                  

    how can i solve the problem on the right way ?

     

    Sunday, July 17, 2011 5:36 PM
  • On 7/17/2011 1:36 PM, lin lewis wrote:
    >
    > i 'd try these code , but useless
    >
    > filterBindingSource.CurrencyManager.Refresh();
    > this.dataGridView1.DataSource = null;
    > this.dataGridView1.DataSource = this.filterBindingSource;
    > this.dataGridView1.Refresh();
    >
    > at last , i rebind the bindingsource and make it , but seems not to be
    > the best.
    >
    > filterBindingSource.DataSource = null;
    > filterBindingSource.DataSource = form_entity.filter;
    >
    > how can i solve the problem on the right way ?
    >
     
    Well, I think you should be reading the data on a round-trip back to the
    database and loading the control based on you going back to read the
    added data from the database.
     
    Tuesday, July 19, 2011 2:25 AM