none
Synchronizing 2 tables RRS feed

  • Question

  • I have 2 Access tables, each having a 1 to 1 relationship.

    I have data in one table listing control signals from a servo controller.

    The second table has antenna control signals.

    The signals have the same names.

    I want to select a signal name in the first table and have the corresponding line with the same signal name highlighted in the second table.

    How do I sync these 2 tables?

    I'm envisioning the same signal name line in each table being highlighted in each table.

    Thursday, October 10, 2019 3:58 PM

All replies

  • Hi,

    Where did you display the two tables? In a form? If so, please refer to the following code.

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'testDataSet1.TableB' table. You can move, or remove it, as needed.
            this.tableBTableAdapter.Fill(this.testDataSet1.TableB);
            // TODO: This line of code loads data into the 'testDataSet.TableA' table. You can move, or remove it, as needed.
            this.tableATableAdapter.Fill(this.testDataSet.TableA);
            dataGridView1.AllowUserToAddRows = false;
            dataGridView2.AllowUserToAddRows = false;
        }
    
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            dataGridView2.ClearSelection();
            if (dataGridView2.Columns[e.ColumnIndex].HeaderText == "name")
            {
                for (int i = 0; i < dataGridView2.Rows.Count; i++)
                {
                    if (dataGridView2.Rows[i].Cells[0].Value.ToString() == dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString())
                    {
                        dataGridView2.Rows[i].Selected = true;
                    }
                }
            }
        }

    Test result,

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 11, 2019 2:03 AM
    Moderator
  • Thanks Kyle,

    I am using a form and your example sure does what I'm looking for.

    I appreciate your feedback.

    Dick Starr

    Friday, October 11, 2019 5:25 PM
  • Hi Dick,

    Since Kyle's reply worked for you, could you come back and mark his reply as an Answer?


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, October 18, 2019 12:36 AM