Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:16:01+00:00 2026-06-04T23:16:01+00:00

I have two DataGirdViews. I want to select rows from right DataGridView and pass

  • 0

I have two DataGirdViews. I want to select rows from right DataGridView and pass them to the left one.
DatGridViews

The right one has 4 columns. In the left grid, I only defined one new column and I want to display this column only. This column is one of columns of the right one, say column[2].
I am stuck here, not sure how to pass the rows?

My incompleted code(maybe error, untested):

 private void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            if (dgRight.CurrentRow != null)
            {
                DataRowView currentDataRowView = (DataRowView)dgRight.CurrentRow.DataBoundItem;
                foreach (DataGridViewRow row in dgRight.Rows)
                {
                    DataGridViewCheckBoxCell check = row.Cells[0] as DataGridViewCheckBoxCell;
                    if (check.Value != null)
                    {
                        if ((bool)check.Value)
                        {
                            //this row has a checkBox set to true (tick is added)
                            //add this row to dataTable ...
                            DataRow myRow = (row.DataBoundItem as DataRowView).Row;
                            DataRow dr = dt.NewRow();

                            if (!dt.Columns.Contains("ID"))
                            {
                                datatableRight.Columns.Add("ID", typeof(int));
                                datatableRight.Columns.Add("col1", typeof(string));
                                datatableRight.Columns.Add("col2", typeof(string));
                                datatableRight.Columns.Add("col3", typeof(string));
                                DataColumn[] keyColumns = new DataColumn[1];
                                keyColumns[0] = datatableRight.Columns["ID"];
                                datatableRight.PrimaryKey = keyColumns;
                            }

                            dr["ID"] = myRow["ID"];
                            dr["col1"] = myRow["col1"];
                            dr["col2"] = myRow["col2"];
                            dr["col3"] = myRow["col3"];

                            if (!datatableRight.Rows.Contains(dr[0]))
                            {
                                datatableRight.Rows.Add(dr);
                            }
                        }
                    }

                }
                dgLeft.DataSource = datatableRight;
                datLeft = datatableRight.Copy();

            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:16:03+00:00Added an answer on June 4, 2026 at 11:16 pm

    Simple use two dataTables with same schema to bind these grids, then Move the rows in DataTables.

    Check this out sample project.
    http://www.zumodrive.com/share/ge0nZmRkMz

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView containing two columns. What I want columns to behave is,
I want to bind columns in a DataGridView to pull values from two different
In My DatagridView ,I Have Two Columns, ComboxboxColumn and TextboxColumn . I want to
I have a DataGridView with two columns member name and member image. I want
I have two datatables. Each has three columns, the two of them have the
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have a DataGridView in which one column has data that the user needs
How do I sort a DataGridView by two columns (ascending)? I have two columns:
I have a DataGridView with two DataGridViewComboBoxColumns. I want to use the selected item
In my Windows Forms Application, basically I have two DataGridView s. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.