More efficient update of data table using TableAdapter -- from more than one textbox or cell in Windows Form? RRS feed

  • Question

  • I am creating an application using C#.  I have one form that has two panels with multiple textboxes and one datagridview.  Each panel and the datagridview have a datatable for its source, for a total of three tables. 
    Within the panel, all the textboxes have the same data table as its source.  My hope was that I could write something that would update the table upon leaving the panel or leaving a row in the datagridview. This seemed more efficient than writing code for each text box or having updates after each cell content change in the data grid view. Is this possible?  If so, why would the following code not work?


    //more efficient edit for related textbox

            private void panel2_LostFocus(object sender, PaintEventArgs e)

                myDate = DateTime.Parse(mysDatetb.Text).Date;
                FirstName = FirstName_tb.Text;
                LastName = LastName_tb.Text;

                dt_myTableAdapter.UpdateTable(myDate, myFirstName, myLastName);
                catch (Exception ex)
                { MessageBox.Show(ex.Message, ex.GetType().ToString() + " panel2_LostFocus"); }

    //more efficient data cell edit?

            private void dataGridView1_OnRowLeave(object sender, DataGridViewCellEventArgs e)
                }//end try
                catch (Exception ex)
                { MessageBox.Show(ex.Message, ex.GetType().ToString() + "SP dgv1_OnRowLeave"); }

    Monday, September 13, 2010 5:22 PM


  • This does work--I needed Event Handlers for the methods in Form1_designer.  panel1_LostFocus was replaced by panel1_Leave.

    this.panel1.Leave += new System.EventHandler(this.panel1_Leave);




    .resultdataGridView1.RowLeave += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_RowLeave);

    Tuesday, September 14, 2010 1:54 PM