DataGridView Not Updating in C# When Binding Source is Correct

I have a DataGridView and an Edit button. When I click the Edit release and change a field, I press Save and the DataGridView comes up again. The problem is that my changes are n’t showing .
Using the debugger, I have looked in the DGV and in the BindingSource and the adjust datum is there. It is just not displaying in the DGV .
hera is my code – I do realize that it is semi-redundant but, at this compass point, I ‘m four hours into it and am volition to try anything .

        this.iSOXTableAdapter.FillByISOX(this.MSDataSet.ISOX);

        BindingSource bindingSource = new BindingSource();
        bindingSource.DataSource = iSOXBindingSource;
        iSOXDataGridView.DataSource = null;
        iSOXDataGridView.DataSource = bindingSource;
        bindingSource.ResetBindings(false);
        this.iSOXDataGridView.Refresh();

I have looked at the following questions ( and many others ) and tried their suggestions to no avail :

Datagridview not updating correctly
dataGridView not updating c # ?
DataGridView not updating in degree centigrade #
Best way to refresh DataGridView when you update the base data beginning

Read more: Events Timeline

How to refresh or show immediately in datagridview after inserting ?
I appreciate any aid or suggestions or ideas for workarounds. Thank you therefore much for looking at this .
* * * * * * * * * * * * * * * * * EDIT * * * * * * * * * * * * * * * * * * *
here is the code for the save button – I know it is working because after I requery the data, it is in the bind source and in the DGV. This code is in a separate add/edit class :

  private void BtnSave_Click(object sender, EventArgs e)
    {
        if (ValidateForm())
        {
            ISOXBindingNavigatorSaveItem_Click(sender, e);
            this.Close();
        }
        else
        {
            MessageBox.Show("Not Validated - Could not Save");
        }

    }

here is wide code for the user control with the DGV on it :

public partial class FindISOXControl : UserControl
{
    private bool gridInitialized = false;

    public delegate void ItemHasBeenSelected(object sender, SelectedItemEventArgs e);
    public event ItemHasBeenSelected SelectedItem;

    public class SelectedItemEventArgs : EventArgs
    {
        public int SelectedChoice { get; set; }
    }

    public bool First = true;

    public FindISOXControl()
    {            
        InitializeComponent();
        FillTableAdapter();
        iSOXDataGridView.Columns.Cast().ToList().ForEach(f => f.SortMode = DataGridViewColumnSortMode.NotSortable);

    }

    public void FillTableAdapter()
    {
        this.iSOXTableAdapter.FillByISOX(this.MSDataSet.ISO);

        BindingSource bindingSource = new BindingSource();
        bindingSource.DataSource = iSOXBindingSource;
        iSOXDataGridView.DataSource = null;
        iSOXDataGridView.DataSource = bindingSource;
        bindingSource.ResetBindings(false);
        this.iSOXDataGridView.Refresh(); 
        setGridData(); 
    }
    public void UpdateISOXText(string pISOX = "")
    {
        this.txtFind.Text = pISOX;
        txtFind.Refresh();
    }
    DataTable dt = new DataTable();
    public void btnFind_Click(object sender, EventArgs e)
    {

        {
            setGridData();
        }
    }
    public void setGridData()
    {
        GetData(); 
        if (iSOXDataGridView.RowCount > 0)
        {
            EventArgs e = new EventArgs();
            iSOXDataGridView_SelectionChanged(null, e);
        }
    }
    public void txtISOX_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Tab)
        {
            setGridData();
        }
    }
    //Query database
    public void GetData()
    {
        String searchValue = txtFind.Text.Trim().ToUpper();
        int rowIndex = -1;
        foreach (DataGridViewRow row in iSOXDataGridView.Rows)
        {
            if (row.Cells[0].Value.ToString().Contains(searchValue))
            {
                rowIndex = row.Index;
                break;
            }
        }
        if (rowIndex == -1)
        {
            foreach (DataGridViewRow row in iSOXDataGridView.Rows)
            {
                if (row.Cells[4].Value.ToString().ToUpper().Contains(searchValue))
                {
                    rowIndex = row.Index;
                    break;
                }

            }
        }
        if (rowIndex == -1)
        {
            if (searchValue != null && searchValue !="")
            { 
                MessageBox.Show(searchValue + " Not Found");
            }
        }
        else
        {
            iSOXDataGridView.Rows[rowIndex].Selected = true;
            iSOXDataGridView.CurrentCell = iSOXDataGridView.Rows[rowIndex].Cells[0];
        }

    }


    public void iSOXDataGridView_SelectionChanged(object sender, EventArgs e)
    {
        if (iSOXDataGridView.CurrentRow != null)
        {
            int Row = iSOXDataGridView.CurrentRow.Index;
            if (gridInitialized)
            {
                txtFind.Text = iSOXDataGridView[0, Row].Value.ToString();
                // 6 is the ID column
                DataGridViewCellEventArgs ev = new DataGridViewCellEventArgs(6, Row);
                iSOXDataGridView_CellDoubleClick(sender, ev);
            }
        }
    }
    private void iSOXDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {

        if (e.RowIndex >= 0 && e.RowIndex < iSOXDataGridView.RowCount)
        {
            // 6 == id column
            int choice = (int)iSOXDataGridView[6, First ? 0 : e.RowIndex].Value;
            this.SelectedItem(this, new SelectedItemEventArgs { SelectedChoice = choice });

        }
    }

    private void iSOXDataGridView_RowEnter(object sender, DataGridViewCellEventArgs e)
    {
        // 6 is the ID column
        DataGridViewCellEventArgs ev = new DataGridViewCellEventArgs(6, e.RowIndex);
        if (e.RowIndex != 0)
        {
            First = false;
            iSOXDataGridView_CellDoubleClick(sender, ev);
        }
    }
    private void iSOXDataGridView_RowLeave(object sender, DataGridViewCellEventArgs e)
    {
        if (e.RowIndex == 0 && e.ColumnIndex == 0)
        { First = true; }
    }
}

here is the code from the independent form with the exploiter dominance on it after it returns from the edit :

   uc.FillTableAdapter(); 

* * * * * * * * * EDIT — > Code that is opening Edit human body :

            AddEditISOX aeix = new AddEditISOX("E", currentISOX);
            aeix.ShowDialog();
            ISOX_Load(sender, e);

           ISOX_Load() calls  uc.FillTableAdapter();
source : https://ontopwiki.com
Category : Finance

Post navigation

Leave a Comment

Trả lời

Email của bạn sẽ không được hiển thị công khai.