C Sharp And Ms Access Database Tutorial 22 How To Show Datagridview Selected Rows To Another Forms Datagridview

C# And Ms Access Database Tutorial #22 – How To Show Datagridview Selected Rows To Another Forms Datagridview Using C#

VIDEO TUTORIAL

C# And Ms Access Database Tutorial #22 – How To Show Datagridview Selected Rows To Another Forms Datagridview Using C#

This Tutorial Shows How To Show Datagridview Selected Rows To Another Forms Datagridview In C# Windows Forms Application using visual studio 2010.

How To Show Datagridview Selected Rows To Another Forms Datagridview
How To Show Datagridview Selected Rows To Another Forms Datagridview
How To Show Datagridview Selected Rows To Another Forms Datagridview DGV
How To Show Datagridview Selected Rows To Another Forms Datagridview DGV

C# SOURCE CODE

        //View Selected Row In Another Forms Datagridview On Button Click
        private void button3_Click(object sender, EventArgs e)
        {
            //If there is altleast One Row Selected
            if (dataGridView1.Rows.Count > 0 && dataGridView1.SelectedRows.Count > 0 )
            {
                ViewSelectedRowInAnotherFormsDatagridview viewSelectedRowInAnotherFormsDatagridviewDGV = new ViewSelectedRowInAnotherFormsDatagridview();
                for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
                {
                    int index =  viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows.Add();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[0].Value = dataGridView1.SelectedRows[i].Cells[0].Value.ToString();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[1].Value = dataGridView1.SelectedRows[i].Cells[1].Value.ToString();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[2].Value = dataGridView1.SelectedRows[i].Cells[2].Value.ToString();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[3].Value = dataGridView1.SelectedRows[i].Cells[3].Value.ToString();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[4].Value = dataGridView1.SelectedRows[i].Cells[4].Value.ToString();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[5].Value = dataGridView1.SelectedRows[i].Cells[5].Value.ToString();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[6].Value = dataGridView1.SelectedRows[i].Cells[6].Value.ToString();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[7].Value = dataGridView1.SelectedRows[i].Cells[7].Value.ToString();
                    viewSelectedRowInAnotherFormsDatagridviewDGV.dataGridView1.Rows[index].Cells[8].Value = dataGridView1.SelectedRows[i].Cells[8].Value;
                }
                viewSelectedRowInAnotherFormsDatagridviewDGV.ShowDialog();
            }
            else if (dataGridView1.Rows.Count > 0 && dataGridView1.SelectedRows.Count == 0)
            {
                MessageBox.Show("dataGridView Has Data But There Is No Row Selected................");
            }
            else if (dataGridView1.Rows.Count == 0)
            {
                MessageBox.Show("dataGridView Has No Data................");
            }
            else
            {
                MessageBox.Show("Unknown Error ................");
            }
        }

Leave a Reply

Your email address will not be published. Required fields are marked *