C Sharp And Ms Access Database Tutorial 21 How To Show Datagridview Selected Row Data In Another Form

C# And Ms Access Database Tutorial #21 – How To Show Datagridview Selected Row Data In Another Form Using C#

VIDEO TUTORIAL

C# And Ms Access Database Tutorial #21 – How To Show Datagridview Selected Row Data In Another Form Using C#

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

C# SOURCE CODE

        //View Selected Datagridview data on new form
        private void btnViewSelectedRowOnNewForm_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 0 && dataGridView1.SelectedRows.Count == 1)
            {
                ViewSelectedDataGridViewRowOnANewForm viewSelectedDataGridViewRowOnANewFormDGV = new ViewSelectedDataGridViewRowOnANewForm();
                viewSelectedDataGridViewRowOnANewFormDGV.txtID.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                viewSelectedDataGridViewRowOnANewFormDGV.txtFullName.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                viewSelectedDataGridViewRowOnANewFormDGV.txtEmailAddess.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                viewSelectedDataGridViewRowOnANewFormDGV.txtPhoneNumber.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                viewSelectedDataGridViewRowOnANewFormDGV.txtLanguage.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
                viewSelectedDataGridViewRowOnANewFormDGV.txtCountry.Text = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
                viewSelectedDataGridViewRowOnANewFormDGV.txtgender.Text = dataGridView1.SelectedRows[0].Cells[6].Value.ToString();
                viewSelectedDataGridViewRowOnANewFormDGV.txtImagePath.Text = dataGridView1.SelectedRows[0].Cells[7].Value.ToString();
                viewSelectedDataGridViewRowOnANewFormDGV.pictureBox1.Image = convertByteArrayToImage((byte[])dataGridView1.SelectedRows[0].Cells[8].Value);
                viewSelectedDataGridViewRowOnANewFormDGV.ShowDialog();

            }
            else if (dataGridView1.Rows.Count == 0 )
            {
                MessageBox.Show("DatagridView Is Empty.............");
            }
            else if (dataGridView1.Rows.Count > 0 && dataGridView1.SelectedRows.Count == 0)
            {
                MessageBox.Show("DatagridView Has Data But There Is No Row Selected.............");
            }
            else if (dataGridView1.SelectedRows.Count > 1)
            {
                MessageBox.Show("You Have Selected More Than One Row. Select Only One Row.............");
            }
        }

Leave a Reply

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