I have two datagrid's in one form,so when i click by using cellclick event it shows the selected row of first datagrid in the second datagrid,so my question is how to increment it with the previous selected row of first datagrid,as i select other row the first selected row disappears??

Could you post the code of your CellClick event handler?

 private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e)
        {

             List<object> destList = new List<object>();
            foreach (DataGridViewRow row in dataGridViewX1.SelectedRows)
                destList.Add(row.DataBoundItem);
            dataGridViewX2.DataSource = destList;




        }



    sir as i select a particular cell the previous cell selected should be there in that second datagrid !!!!

sir as i select a particular cell the previous cell selected should be there in that second datagrid !!!!

Apologies but I don't fully understand your question.

When you click a row in the first dataGridView, do you want to select that same row in the second dataGridView?.

It would be easier to understand what you are trying to do if you post screen shots from the program. As an alternative, you could create tables in Word/Wordpad that represent the two datagridviews and post those-describing what you desire to accomplish.

here i've the following Screen shots!! ! a05e3392bb3fc92946f57e04c09bc5697aa95aeaea72895d2f3fba2fb289ad325d43f0571c8b14f2c003fbd255eafd27

so as i select a particular row from 1st datagrid its shows the selected row on the second datagrid,but if i select another row from first datagrid the row that was previously been selected goes away and shows the current selected row!!!

Put this List<object> destList = new List<object>(); outside of your method. You are creating a new list every time you click and then add just one element to it.

sir that's not showing the previous selected row in that datagrid2
after selecting any row from 1st datagrid,the records in 2nd datagrid must show active selected rows as well as previously inactive selected rows
the second datagrid is'nt incrementing !!!!!

I tried this code, and it seems to work:

private void DGV1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            foreach (DataGridViewRow row in DGV1.SelectedRows)
            {
                int index = DGV2.Rows.Add(row.Clone());
                foreach (DataGridViewCell cell in row.Cells)
                {
                    DGV2.Rows[index].Cells[cell.ColumnIndex].Value = cell.Value;
                }   
            }
        }

Sir it's giving an error!!!! 03bc678b6f81e104bd5e4e94360d266c

Did you read what the error message told you?
Before you can add any row to your second DGV you must make sure that it contains columns.

Sir Thank YOu very much it helped !!!!! !

50838d7c2c569eac2efbd9c7256c4def

sir one more thing how should i prevent duplicate rows???

A possibility might be to have an extra column in your DGV containing transfer info. You could check this info before adding the row to the second DGV.
You can always hide a column from the user with
this.DGV.Columns[colNr].Visible = false;

Nice picture BTW :)

Thank u Sir!!
Sir can u give that full code plz!!

Hé, you are a software engineer, aren't you?
Should be a piece of cake!

ya sir n thank u very much!!!! a1ab8fbe1c21af213d382bebc0a1b61d

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.