none
data grid view data binding problem RRS feed

  • Question

  • Hi,

    I am using a DataGridview control for displaying TOC of a Book. The windows application reads book information
    from the database and displays the TOC of the book in a Grid. It works fine for the first or default book. But when
    I select the Book from a combobox , the grid should rebind the data according to the book selected from the combobox.
    when i step through the debug process, all the steps works fine, even the data source also showing the updated records
    for the new book selected. But when returning to the application the Grid show the previous result, not the new one.
    why it occurs? what is the solution to this.

    Steps taken:
    -----------------
    1. Cleared the Grid before each bind, but no use
    2. used Binding source but no effect
    3. used Refresh(), update() methods but nothing changed
    4. The following function is the one I wrote to dynamically bind the contents.


    Code Snippet

    void BindContents(string bid, string issue)
            {
                dgContents.Columns.Clear();
                XMLCreate obj = new XMLCreate();
                DataTable dtContent = obj.Contents(int.Parse(bid), int.Parse(issue));
                if (dtContent.Rows.Count > 0)
                {
                    dgContents.Columns.Clear();
                    dgContents.DataSource = dtContent;
                    dgContents.CellClick += new DataGridViewCellEventHandler(dgContents_CellClick);
                }
                else
                {
                    dgContents.Visible = false;
                    lblContents.Visible = true;
                }

            }


    Can any one give solution for this.
    karthik

    Monday, April 2, 2007 11:00 AM

Answers

  • Hi

       Try this method, I save date in this way,hope it helps

     

       Private Sub EmployeesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployeesBindingNavigatorSaveItem.Click

            Me.Validate()

            Me.EmployeesBindingSource.EndEdit()

            Me.EmployeesTableAdapter.Update(Me.NorthwindDataSet.Employees)

    End Sub

     

    Wednesday, April 4, 2007 7:40 AM

All replies

  • Are you sure XMLCreate is returning what you think?


    Tuesday, April 3, 2007 12:04 AM
  • yes, it returns the datatable with required records and even the datatable binds to the grid.
    karthik
    Tuesday, April 3, 2007 4:39 AM
  • Hi

       Try this method, I save date in this way,hope it helps

     

       Private Sub EmployeesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployeesBindingNavigatorSaveItem.Click

            Me.Validate()

            Me.EmployeesBindingSource.EndEdit()

            Me.EmployeesTableAdapter.Update(Me.NorthwindDataSet.Employees)

    End Sub

     

    Wednesday, April 4, 2007 7:40 AM