none
How do you refresh data bound to a DataGridView

    Question

  •  

    This should be easy... but I don't know how to do it.

    I have created a DataSet that is bound to a DataGridView so that the DataGridView displays the data in my DataSet.  If my DataGridView is called dgvStudents, the following code DOES NOT do the job:

    dgvStudents.Refresh();

    I can see the grid itself flash and refresh(), but the data behind the grid is not being refreshed, so new items in the database (added by another process) are not being displayed in the grid.

    How do you do this?

     

    Friday, December 16, 2005 11:55 PM

Answers

  •  

    That still doesn't seem to be doing the trick.  I was able to finally get it to work with the following code:

    this.rscan_queueTableAdapter.Fill(this.rscanDataSet.rscan_queue);

    dgv_queue.refresh();

     

    I haven't looked deeply into the above code yet to see if there are performance hits I will take by doing the above.

    Wednesday, December 21, 2005 11:46 PM
  • First, end any edits in the grid view:

    this.dataGridView1.EndEdit();

    Second, refresh the grid view:

    this.dataGridView1.Refresh();

    You may even have to repaint the container control (using Refresh() also).

     If it's data you're trying to retrieve, re-fill the DataSet you're using with the grid view.

    Tuesday, February 07, 2006 4:53 PM

All replies

  • Yes, this is sometimes tricky. That's because of Painting AND edit modes. Even though you're calling the DataGridView's Refresh method, the underlying functionality may not end up doing anything if it thinks you're currently editing the grid (edit mode) and it's determined there are no real changes to repaint. Also, sometimes calling Refresh on the child control doesn't work alone - you need to additionally call the parent control's Refresh method.
     
    So, I would suggest taking both approaches:
     
    1)  Call the EndCurrentEdit() method of the DataGridView's BindingContext.
    2) Refresh first the DataGridView and then the Parent (usually the Form) .
     

    this.BindingContext[this.dataGridView1.DataSource].EndCurrentEdit();

    // If the DataGridView has a DataMember set then:

    this.BindingContext[this.dataGridView1.DataSource, "MemberName"].EndCurrentEdit();

    this.dataGridView1.Refresh(); // Make sure this comes first

    this.dataGridView1.Parent.Refresh(); // Make sure this comes second

    Saturday, December 17, 2005 12:32 AM
  •  

    Thank you for your response.  I've tried that now and it still doesn't seem to be doing a refresh.  The refresh only occurs when I exit the application and go back in.

     

    Wednesday, December 21, 2005 9:03 PM
  • That should work. I wrote something about this on my blog a while back, here it is:

  • Properly Updating Data Grid Bound Values: If you ever run into a situation where you have a Data Grid bound to a Data Source and another control, such as a TextBox or ComboBox, and it's bound to the same Data Source and modifying the bound value of that control does not immediately cause the modified value to appear in the Data Grid, I have the reason why: validation. Normally, when a situation like this occurs, simply tabbing through the controls causes the modified value to appear in the bound Data Grid. That's because the validation events are raised which in return call the control's Refresh() method. Refresh() causes the bound control(s) to invalidate their area and redraw. This includes, in this example, any data within a Data Grid. In order for you to properly update a bound Data Grid's data whenever a bound control modifies it's values, you need to 1) first place the Focus() on the container that holds the Data Grid (a Form, GroupBox, etc.), 2) secondly, place the Focus() on the Data Grid itself and then 3) thirdly, call the Data Grid's Refresh() method.
Wednesday, December 21, 2005 11:31 PM
  •  

    That still doesn't seem to be doing the trick.  I was able to finally get it to work with the following code:

    this.rscan_queueTableAdapter.Fill(this.rscanDataSet.rscan_queue);

    dgv_queue.refresh();

     

    I haven't looked deeply into the above code yet to see if there are performance hits I will take by doing the above.

    Wednesday, December 21, 2005 11:46 PM
  • Oh, I see, I must've misunderstood what you were trying to do. I thought you were modifying a DataRow and wanted to see the changes in the DataGridView. Rather, what you're trying to do is simply refresh the DataSet from a Data Source, correct?
    Wednesday, December 21, 2005 11:47 PM
  •  

    There is a process running on various machines that adds entries to a database.  This particular grid acts as a work queue for the user (simply displaying entries from the database).  When the database gets new values added to it (by other processes), the grid has to update (on the next refresh that occurs via the timer).

    Is there a better way to implement this?  Sorry I threw you for a loop by not being clear in the initial question.  Thank you for your responses.

    The code seems to work now, but one of the things I am experiencing is a horrible white flash.  Based upon a value in a particular column, the datagridview's paint even sets a rows background color (to indicate priority).  When the gridrefreshes using the above method, the grid flashes white and then recolors everything.

    Wednesday, December 21, 2005 11:55 PM
  • Avoid Flashing in the grid by using BeginUpdate and Endupdate

     

    Thursday, December 22, 2005 6:57 AM
  •  

    Hmmm... I don't see a beginupdate and endupdate for the grid object.

    Friday, December 23, 2005 5:24 PM
  •  

    Anyone know how to refresh this?

    Thursday, January 26, 2006 11:55 PM
  • First, end any edits in the grid view:

    this.dataGridView1.EndEdit();

    Second, refresh the grid view:

    this.dataGridView1.Refresh();

    You may even have to repaint the container control (using Refresh() also).

     If it's data you're trying to retrieve, re-fill the DataSet you're using with the grid view.

    Tuesday, February 07, 2006 4:53 PM
  • You should refresh tables of your DataSet.
    For example :
    yourDataSet.table1.fill();

    In my case, I have just one table to refresh but you can do this for all tables of your dataset.

    I hope it will help you.

    Julien



    Monday, February 20, 2006 1:54 PM
  • TableAdapter.Fill
    DataGridView.refresh()

    worked for me, i hope it will help you

    Regards

    jlgervais
    • Proposed as answer by sairenji Wednesday, May 06, 2009 6:50 AM
    Monday, February 27, 2006 8:05 PM
  • or you can refresh your bindingsource:

    myBindingSource.ResetBindings();

    goodluck

    Tuesday, February 28, 2006 3:18 AM
  • Possibly I should post this as a new thread but I believe I'm running into a similar situation. I have a DataGridView DataSource that  is being populated by  a List:

    private void PopulateCategories()
    {
        //GetCategoriesForBusinessUnit(businessUnitId) returns a List 
        this.categoriesGridView.DataSource = CategoryService.GetCategoryService().GetCategoriesForBusinessUnit(businessUnitId);
    }

    The problem is when I do an insert. The flow of events is an insert takes place on the backend, and afterwards when this control is notified of the event the PopulateCategories() method above is called. The problem is the newly inserted row is not reflected in the UI (even though the method is returning it correctly) so I'm guessing it has something to do with how stuff is bound.

    What does work is if I make the DataSource null first and the populate it:

    this.categoriesGridView.DataSource = null;
                 this.categoriesGridView.DataSource = CategoryService.GetCategoryService().GetCategoriesForBusinessUnit(businessUnitId);
               
    Is this the correct way to do it (declaring the DataSource null first?). I've tried some of the other ideas in this post, but none of them seemed to work. Thanks for any advice.

    Monday, March 13, 2006 3:35 PM
  • Using a fill to refresh seems like it would be a very slow process.  It is amazing to me that the control does not have an automatic refresh that changes only the information rows that have changed since the last refresh.

     

     

    Wednesday, May 17, 2006 11:01 PM
  • icemart525 has a workable solution:

    myBindingSource.ResetBindings();

    This does in fact solve a similar problem I have been experiencing.  My issue also dealt with many datasources and many bindings.  Upon trying to refresh my data, I was needlessly using table addapters to re-read and then rebind my data. 

    ResetBindings really cleaned up my code and it it works smoothly.

    Thanks!

    --SputnikCoder

    Friday, September 01, 2006 5:10 AM
  • This is off topic for the Visual C# General forum, moving the Windows Forms Data Controls and Databinding forum.
    Saturday, September 02, 2006 3:37 PM
  • The problem here is that your dataset is disconnected from the database, so your datagrid is updating correctly, but the dataset is not changed.

    You could use SQL changenotification events (google it) but this requires changes in the SQL server setup. After the change notification you'll have to update (or completely re-fill) yur dataset and then refresh the datagridview.

    Another (quick and dirty) solution would be polling, where you check the database every X time for updates.

    If no changes to the DB setup are possible you might want to look for another way to have the changing (external) applications communicate to the displaying application that they have changed data in the SQL database.

     

    Hope this helped,

    Ben.

    Tuesday, September 05, 2006 8:03 AM
  • Before changing datasource of datagridview, use the code

    DataGridView1.Rows.Clear();

    and then bind the new  datasource. i think it can solve your problem.

    Tuesday, September 11, 2007 11:33 AM
  • try this, this works for me.

                EmployeeDataSet.GetChanges()

    hopefully it will work for you
    Wednesday, September 12, 2007 2:01 PM
  • ((CurrencyManager)dgvSelect.BindingContext[soreSelect]).Refresh();
    Friday, August 22, 2008 5:49 PM
  • I was really frustrated recently because of that problem. I know this is an old post but here what was my problem and how I solved it (for those who want another alternate solution).

    I had a List<MyItems> set as datasource of my datagridview. I had some row template binded to the names of my class (MyItem). Everything was working fine. To do a refresh, I just used my default hack: set the datasource to null and set it back to my list. This solution works quite well.

    But for some unknown reason, I had one case that when I was using this method, my row template were discarted (or ignored). So, I've tried everything I found on the net to do it properly instead of this "null" method. I don't know if the reason is that I was calling Invoke in a different thread in order to get an update, but anyway, I had to find a working solution.

    So, the solution I found is quite hack-ish, but it's the only one working so far:
    SuspendLayout(); // optional line
    myDataGridView.Parent = null; // this is where the magic begins
    // you can do stuff here as well if you want.
    Controls.Add(myDataGridView); // add it back where it belongs.
    ResumeLayout(); // optional line


    So, it seems that, by just unparenting it, it triggers a full reconstruction of the datagridview. This is what I would expect from the Refresh() method I suppose.
    Thursday, January 22, 2009 10:21 PM
  •  

    This should be easy... but I don't know how to do it.

    I have created a DataSet that is bound to a DataGridView so that the DataGridView displays the data in my DataSet.  If my DataGridView is called dgvStudents, the following code DOES NOT do the job:

    dgvStudents.Refresh();

    I can see the grid itself flash and refresh(), but the data behind the grid is not being refreshed, so new items in the database (added by another process) are not being displayed in the grid.

    How do you do this?

     


    Just do one thing...put the while data fetching method in s different function and then call that function on that buttn click.

    Something like this....

    using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.ComponentModel;

    using

     

    System.Data;

    using

     

    System.Drawing;

    using

     

    System.Text;

    using

     

    System.Windows.Forms;

    using

     

    System.Data.SqlClient;

    namespace

     

    DataWinEx

    {

     

    public partial class Form1 : Form

    {

     

    public Form1()

    {

    InitializeComponent();

    }

     

    private void con()

    {

     

    SqlConnection con = new SqlConnection("server=ABHI\\SQLEXPRESS;database=Employee;uid=kaushik;pwd=sagar;");

    con.Open();

     

    String s;

    s =

    "Select * from Emp";

     

    SqlCommand cmd = new SqlCommand(s, con);

     

    SqlDataAdapter da = new SqlDataAdapter(s, con);

     

    DataSet ds = new DataSet();

    da.Fill(ds,

    "Emp");

    dataGridView1.DataSource = ds;

    dataGridView1.DataMember =

    "Emp";

    con.Close();

    }

     

    private void Form1_Load(object sender, EventArgs e)

    {

     

    this.con();

    }

     

    private void button1_Click(object sender, EventArgs e)

    {

     

    SqlConnection con = new SqlConnection("server=ABHI\\SQLEXPRESS;database=Employee;uid=kaushik;pwd=sagar;");

    con.Open();

     

    SqlCommand cmd = new SqlCommand("Insert into Emp values(" + textBox1.Text + ",'" + textBox2.Text + "')",con);

     

     

    int n = cmd.ExecuteNonQuery();

     

    MessageBox.Show("Record Gets Added...");

     

    this.con();

    }

    }

    }

    Monday, May 25, 2009 6:39 PM
  • using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.ComponentModel;

    using

     

    System.Data;

    using

     

    System.Drawing;

    using

     

    System.Text;

    using

     

    System.Windows.Forms;

    using

     

    System.Data.SqlClient;

    namespace

     

    DataWinEx

    {

     

    public partial class Form1 : Form

    {

     

    public Form1()

    {

    InitializeComponent();

    }

     

    private void con()

    {

     

    SqlConnection con = new SqlConnection("server=ABHI\\SQLEXPRESS;database=Employee;uid=kaushik;pwd=sagar;");

    con.Open();

     

    String s;

    s =

    "Select * from Emp";

     

    SqlCommand cmd = new SqlCommand(s, con);

     

    SqlDataAdapter da = new SqlDataAdapter(s, con);

     

    DataSet ds = new DataSet();

    da.Fill(ds,

    "Emp");

    dataGridView1.DataSource = ds;

    dataGridView1.DataMember =

    "Emp";

    con.Close();

    }

     

    private void Form1_Load(object sender, EventArgs e)

    {

     

    this.con();

    }

     

    private void button1_Click(object sender, EventArgs e)

    {

     

    SqlConnection con = new SqlConnection("server=ABHI\\SQLEXPRESS;database=Employee;uid=kaushik;pwd=sagar;");

    con.Open();

     

    SqlCommand cmd = new SqlCommand("Insert into Emp values(" + textBox1.Text + ",'" + textBox2.Text + "')",con);

     

     

    int n = cmd.ExecuteNonQuery();

     

    MessageBox.Show("Record Gets Added...");

     

    this.con();

    }

    }

    }

    Monday, May 25, 2009 6:40 PM
  • Hi.
    This is vary usefull to me.
    Thanx..
    Thursday, November 05, 2009 9:04 AM
  • myTableAdapter.Fill(myDataSet.myTable);
    myDataGridView.Invalidate();
    myDataGridView.Refresh();
    Wednesday, February 03, 2010 7:34 PM
  • I just have to say thanks for asking this question and finding the answer. I spent three months trying to figure this out in VB.net and your code here enabled me to finally figure out how to do it!!!

    Thank you for asking and thanks to DotNetFun for trying to help out.

    You two have no idea how much this means to me and my life!

    I know y'all posted this forever ago but you are truly a Godsend. Thanks be to Him for all of this also.

    Saturday, March 20, 2010 12:57 AM
  • I think this simple trick is fine, because Refresh() gives us a performance penalty by redrawing the whole control; the technique is to rebound the datasource;

     

    myDataGridView.DataSource = null;
    myDataGridView.DataSource = GetRecordsList();

    Saturday, May 29, 2010 6:53 PM
  • Yeah this solution works for me! Thanks Rickcr

    You need to make the Datasource have the null value before assign the new datasouce otherwise it wouldn't refresh at all in DGV.

    Instead of a DataSet, I have an List<Object>, everytime that a new object is added to the List or erased from the List, I have to null the property "DataSource" on the DGV before assign the List with the changes.

    Regards.

     

    Wednesday, August 25, 2010 2:48 AM
  • I was frustrated with that problem too!!

    I had a list of class Items in this way --> List<Items> ListItems;

    Everytime that the list is modified by erasing or inserting an element within the list, I have to execute this sentences to update it in the DataGridView --> DGmain

    DGmain.DataSource = null;

    DGmain.DataSource = ListItems;

    DGmain.Columns["NameCol1"].DisplayIndex = 0;

    DGmain.Columns["NameCol2"].DisplayIndex = 1;
    DGmain.Columns["NameCol3"].DisplayIndex = 2;          


    So in this way, you could avoid the unpleasant result of your row template being changed everytime that you List is modified.

    I don't know if there another workaround or some property that I have to enable/disable to avoid this.

    Hope this works for anyother.

     

    Regards.

     

     

    Wednesday, August 25, 2010 3:07 AM
  • Hi,

     

     

            private void refresh()
    
            {
    
                int pos = BindingContext[yourDataset].Position;
    
                yourDataset.Clear();
    
                yourDataAdapter.Fill(yourDataset);
    
                BindingContext[yourDataset].Position = pos;
    
            }
    

     

    Tuesday, November 02, 2010 10:59 PM
  • I have tried all given solutions..

    The best one is

    tableadapter1.Fill(dataset1.table1);

    datagridView1.invalidate();

    datagridview1.refresh();

     

    P.S : This is the only one which workied..!

     

    Tuesday, February 01, 2011 7:50 PM
  • Thank you! 

    Below code worked..

    tableadapter1.Fill(dataset1.table1);

    datagridView1.invalidate();

    datagridview1.refresh();

     

    Saturday, April 02, 2011 12:30 AM
  • thanks from u im really need it

    other codes donsent work

    thanks again

     

    Saturday, May 28, 2011 9:09 AM
  • Thanks a lot,

    this was what I was looking for,

    really nice way to do :) helped me so much

    Monday, June 06, 2011 2:16 PM
  • I was really frustrated recently because of that problem. I know this is an old post but here what was my problem and how I solved it (for those who want another alternate solution).

    I had a List<MyItems> set as datasource of my datagridview. I had some row template binded to the names of my class (MyItem). Everything was working fine. To do a refresh, I just used my default hack: set the datasource to null and set it back to my list. This solution works quite well.

    But for some unknown reason, I had one case that when I was using this method, my row template were discarted (or ignored). So, I've tried everything I found on the net to do it properly instead of this "null" method. I don't know if the reason is that I was calling Invoke in a different thread in order to get an update, but anyway, I had to find a working solution.

    So, the solution I found is quite hack-ish, but it's the only one working so far:
    SuspendLayout(); // optional line
    myDataGridView.Parent = null; // this is where the magic begins
    // you can do stuff here as well if you want.
    Controls.Add(myDataGridView); // add it back where it belongs.
    ResumeLayout(); // optional line


    So, it seems that, by just unparenting it, it triggers a full reconstruction of the datagridview. This is what I would expect from the Refresh() method I suppose.


    I tried everything on this page.  I'm using a BindingList as my DataSource and this post is the only thing that worked.

     

     

    private void CorrectDataGridRefresh(Control

    dg)

    {

     

    Control

    c = dg.Parent;

    dg.Parent =

    null

    ;

    c.Controls.Add(dg);

    }

    Wednesday, June 22, 2011 8:29 PM
  • Sooo many posts already but I had to add my two cents as I just solved this.

    Calling the Repaint or Refresh method probably won't do much. I'm pretty sure those just deal with painting and not data. You need to re-bind the data, which is easier than it sounds.

    Here:

    object src = this.dataGridTasks.DataSource; // temp variable

    this.dataGridTasks.DataSource = null; // unbind

    // modify bound (now unbound) data set here

    this.dataGridTasks.DataSource = src; // rebind

     

    There will probably be discrepancies because there are a few different ways to bind data to different controls. But this process will work every time: Unbind, modify, rebind.

    (Possibly call refresh if the control isn't being repainted after.)

    • Proposed as answer by cjr9968 Wednesday, July 06, 2011 9:41 PM
    Wednesday, July 06, 2011 9:41 PM
  • Hello,

     

    I have the same problem using VB.NET.

     

    I have tryed all the samples above. But whatever I do. The DataGridView is not only showing the new data it ad's the existing rows with a new listing with the old rows included, when I start with 17 rows it showes 35 rows. I use a OracleDataAdapter when loading the form and try to clear it with OracleDataAdapteDispose and query a new select. Try to clean the DataGridView with Me.DataGridView2.Rows.Clear(). It seems that the old rows are stil there and new rows are added moslty double.

    Now I have tryed it with a new OracleDataAdapter the same result the old rows are still showed.

    The new new row is showing once and all the old rows twice

    This is the code I use

            Dim OracleConn As New OracleConnection("Data Source= Omgeving; User Id=" & username & ";" & "Password=" & password & ";")
            Dim myAdapter As New OracleDataAdapter("Select string here", OracleConn)
            WaboCategorieWaboOnderdeel11.RejectChanges() ( I have tryed this but it look useless)
            DataGridView2.DataSource = WaboCategorieWaboOnderdeel11BindingSource
            DataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            myAdapter.Fill(WaboCategorieWaboOnderdeel11.WaboCategorieWaboOnderdeel)

    Monday, September 12, 2011 8:52 PM
  • Ok I have found it.

    I first cleared the myAdapter, then cleared the dataset after suspendbinding the datasource then I resumebinding the datasource and fill the dataset with myAdapter.Fill. And it's working.

    Dim OracleConn As New OracleConnection("Data Source= Omgeving; User Id=" & username & ";" & "Password=" & password & ";")
    Dim myAdapter As New OracleDataAdapter("Select string here", OracleConn)
    myAdapter.Dispose()
    WaboCategorieWaboOnderdeel11BindingSource.SuspendBinding()
    WaboCategorieWaboOnderdeel11.Clear()
    WaboCategorieWaboOnderdeel11BindingSource.ResumeBinding()
    myAdapter.Fill(WaboCategorieWaboOnderdeel11.WaboCategorieWaboOnderdeel)

    Thanks for reading need no help anymore or you must have a better way

     

     


    Tuesday, September 13, 2011 9:22 PM
  • Be sure that the changes you are making have been committed to the database.  This needs to be done explicitly if your are using an OleDbConnection.  Add a OleDbTransaction object and use it to open and close the transaction.  Explicitly closing the connection should also do the trick, but this is what worked best for me.

    public void ExecuteTransaction(string connectionString)
    {
    using (OleDbConnection connection =
    new OleDbConnection(connectionString))
    {
    OleDbCommand command = new OleDbCommand();
    OleDbTransaction transaction = null;

    // Set the Connection to the new OleDbConnection.
    command.Connection = connection;

    // Open the connection and execute the transaction.
    try
    {
    connection.Open();

    // Start a local transaction
    transaction = connection.BeginTransaction();

    // Assign transaction object for a pending local transaction.
    command.Connection = connection;
    command.Transaction = transaction;

    // Execute the commands.
    command.CommandText =
    "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
    command.ExecuteNonQuery();
    command.CommandText =
    "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
    command.ExecuteNonQuery();

    // Commit the transaction.
    transaction.Commit();
    Console.WriteLine("Both records are written to database.");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    try
    {
    // Attempt to roll back the transaction.
    transaction.Rollback();
    }
    catch
    {
    // Do nothing here; transaction is not active.
    }
    }
    // The connection is automatically closed when the
    // code exits the using block.
    }
    }
    Wednesday, September 28, 2011 10:04 PM
  • These code, works for me thanks!!

    tableadapter1.Fill(dataset1.table1);

    datagridView1.invalidate();

    datagridview1.refresh();

    Wednesday, November 16, 2011 5:13 PM
  • objectGridView.UpdateRow(0, true);

    Simple truco actualizar la fila 0 y se actualiza la tabla

    Saturday, February 18, 2012 7:41 PM
  • Use a BindingList<MyItem> instead of List<MyItem>
    Monday, March 12, 2012 4:40 PM
  • dataGridView.DataSource = null;

    dataTable = new DataTable();//refresh the data table

    dataAdapter.Fill(dTable);

    bindingSource.DataSource = dataTable; //point the data source to the new table

    dataGridView.DataSource = bindingSource; //bind the DataGridView with the new table

    Wednesday, March 28, 2012 11:36 AM
  • WEll m facing the same problem n the above method didnt work for me
    Tuesday, July 03, 2012 9:58 PM
  •            

                 

                  This works Fine ...

                  this.TableAdapter.Fill(this.Dataset.DataTable);

    Monday, July 16, 2012 2:16 PM
  • I know this is an old thread but this is how it worked for me. I have a refresh button and I added the code there. I am using Access.

    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
            Dim Str As String
            Dim dt As New DataTable

            Dim Connection As String = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = Your Database Source"
            Using Con As New OleDbConnection(Connection)
                Try
                    Con.Open()
                    Str = "Select * from Table "
                    Cmd = New OleDbCommand(Str, Con)
                    Cmd.ExecuteNonQuery()
                    dt.Load(Cmd.ExecuteReader())
                    TktBindingSource.DataSource = dt
                    DataGridView1.DataSource = TktBindingSource

                    Cmd.Dispose()
                    Con.Close()

                Catch Ex As Exception
                    MsgBox(Ex.Message)
                End Try
            End Using

    End Sub

    I have a binding source control called tktBindingsource already mapped to a table on my DB. The datasource of that Binding source is a DataSet to my DB.

    Regards,

    Monday, December 30, 2013 5:23 PM
  •  I'd suggest using the Parent property of the Data Grid View object to get hold of the parent windows forms object handler and use Validate() method.

    For example, for a data grid view object taking place in a splitter panel object in a split container object ultimately, I would  code it in Visual C++ like:

    /* assuming there is already a Data Grid View object created with the name "dgv", "dgv->Parent" points to the splitter panel object. Parent of this object is the split container object itself that we are after. */

    SplitContainer^ dgvContainer = dynamic_cast<SplitContainer^>(dgv->Parent->Parent); 

    dgvContainer->Validate();

    That's it.

    Mehmet

    Wednesday, January 08, 2014 1:47 PM
  • private void btnSearchMachine_Click(object sender, EventArgs e) { // Refresh the DataGridView so the search can pull the new data this.tbl_machinesTableAdapter.Fill(this.ds_machines.tbl_machines);

    // Search the DataGridView binding source

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                tblmachinesBindingSource.Filter = string.Format("{0} Like '{1}%'", dropDownValue, searchValue);

    }

    All I had to do was re-fill the DataSet with my new data from the table.  It happens every time the user presses my search button.

    Thursday, February 13, 2014 5:00 PM