VB.NET - How To Display DataGridView Row Checked Cell In Another DataGridView Using VB NET

vb datagridview row to another datagridview


VB.NET - How To Show The DataGridView Rows Checked Cell In Another DataGridView Using VB NET

                                                                                                                         

In This VB.NET Tutorial  We Will See How To Get Checked Rows From DataGridView And Set Them To Another  Datagridview In VBNET Programming Language.


Project Source Code:

Public Class VB_Dispaly_Datagridview_Checked_Row_To_Another_GridView

    Private Sub VB_Dispaly_Datagridview_Checked_Row_To_Another_GridView_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'create a text columns
        Dim dgvcId As New DataGridViewTextBoxColumn()
        dgvcId.HeaderText = "Id"
        Dim dgvcFn As New DataGridViewTextBoxColumn()
        dgvcFn.HeaderText = "First Name"
        Dim dgvcLn As New DataGridViewTextBoxColumn()
        dgvcLn.HeaderText = "Last Name"

        'create checkbox column
        Dim dgvcCheckBox As New DataGridViewCheckBoxColumn()
        dgvcCheckBox.HeaderText = "Select"

       'add columns to datagridview
        DataGridView1.Columns.Add(dgvcId)
        DataGridView1.Columns.Add(dgvcFn)
        DataGridView1.Columns.Add(dgvcLn)
        DataGridView1.Columns.Add(dgvcCheckBox)

            ' add some row to datagridview
            ' true the checkBox Is checked
            ' false the checkBox Is Not checked
        DataGridView1.Rows.Add("1", "DTYUI", "RTYUI", False)
        DataGridView1.Rows.Add("2", "KJHGF", "OIUY", False)
        DataGridView1.Rows.Add("3", "SDFGH", "LTDFGH", False)
        DataGridView1.Rows.Add("4", "ERJHGV", "CVHEYH", False)
        DataGridView1.Rows.Add("5", "AQSFGHKK", "TRDFHJH", False)
        DataGridView1.Rows.Add("6", "NQAAZTYI", "KITGHKG", False)
        DataGridView1.Rows.Add("7", "XBVSARY", "OTYHNC", False)
        DataGridView1.Rows.Add("8", "ACJKT", "PMLGESB", False)
        DataGridView1.Rows.Add("9", "FGHKL", "IUYTEYK", False)
        DataGridView1.Rows.Add("10", "WQAZR", "ERTYUVBD", False)
        DataGridView1.Rows.Add("11", "CKKTS", "EGCQA", False)

        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView1.AllowUserToAddRows = False


        'columns for dataGridView2
        Dim dgvcId2 As New DataGridViewTextBoxColumn()
        dgvcId2.HeaderText = "Id"
        Dim dgvcFn2 As New DataGridViewTextBoxColumn()
        dgvcFn2.HeaderText = "First Name"
        Dim dgvcLn2 As New DataGridViewTextBoxColumn()
        dgvcLn2.HeaderText = "Last Name"
        Dim dgvcCheckBox2 As New DataGridViewCheckBoxColumn()
        dgvcCheckBox2.HeaderText = "Select"
        DataGridView2.Columns.Add(dgvcId2)
        DataGridView2.Columns.Add(dgvcFn2)
        DataGridView2.Columns.Add(dgvcLn2)
        DataGridView2.Columns.Add(dgvcCheckBox2)
        DataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView2.AllowUserToAddRows = False
    End Sub

    Private Sub BtbDisplay_Click(sender As Object, e As EventArgs) Handles BtbDisplay.Click

        ' loop to check if the checkbox cell is checked
        For i As Integer = 0 To DataGridView1.Rows.Count() - 1 Step +1

        ' rowAlreadyExist => if the row already exist on dataGridView2
            Dim rowAlreadyExist As Boolean = False
            Dim check As Boolean = DataGridView1.Rows(i).Cells(3).Value
            Dim row As DataGridViewRow = DataGridView1.Rows(i)
            If check = True Then

             ' the dataGridView2 have one row or more
                If DataGridView2.Rows.Count() > 0 Then

                   ' loop to see if the row already exist on dataGridView2
                    For j As Integer = 0 To DataGridView2.Rows.Count() - 1 Step +1
                        If row.Cells(0).Value.ToString() = DataGridView2.Rows(j).Cells(0).Value.ToString() Then
                            rowAlreadyExist = True
                            Exit For

                        End If
                    Next

                    If rowAlreadyExist = False Then
                        DataGridView2.Rows.Add(row.Cells(0).Value.ToString(),
                                               row.Cells(1).Value.ToString(),
                                               row.Cells(2).Value.ToString(),
                                               row.Cells(3).Value)
                    End If

                Else
                    DataGridView2.Rows.Add(row.Cells(0).Value.ToString(),
                                                   row.Cells(1).Value.ToString(),
                                                   row.Cells(2).Value.ToString(),
                                                   row.Cells(3).Value)

                End If
            End If
            

        Next

    End Sub
End Class
      
///////////////OUTPUT:





vb display datagridview row to another datagridview
datagridview row to another datagridview




VB.NET - How To Delete DataGridView Row Checked Cell In VB NET


vb delete datagridview row

VB.NET - How To Remove The Checked Row From Datagridview Using VB NET

                                                                                                                         

In This VB.NET Tutorial  We Will See How To Delete The DataGridView Row With  CheckBox ( Checked  Cell Is Checked ) In VBNET Programming Language.


Project Source Code:

Public Class VB_delete_datagridview_Row_checked_checkbox_cell

    Private Sub VB_delete_datagridview_Row_checked_checkbox_cell_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'create a text columns
        Dim dgvcId As New DataGridViewTextBoxColumn()
        dgvcId.HeaderText = "Id"
        Dim dgvcFn As New DataGridViewTextBoxColumn()
        dgvcFn.HeaderText = "First Name"
        Dim dgvcLn As New DataGridViewTextBoxColumn()
        dgvcLn.HeaderText = "Last Name"

        'create checkbox column
        Dim dgvcCheckBox As New DataGridViewCheckBoxColumn()
        dgvcCheckBox.HeaderText = "Delete"

        'add columns to datagridview
        DataGridView1.Columns.Add(dgvcId)
        DataGridView1.Columns.Add(dgvcFn)
        DataGridView1.Columns.Add(dgvcLn)
        DataGridView1.Columns.Add(dgvcCheckBox)

        ' add some row to datagridview
        ' true the checkBox Is checked
        ' false the checkBox Is Not checked
        DataGridView1.Rows.Add("1", "DTYUI", "RTYUI", False)
        DataGridView1.Rows.Add("2", "KJHGF", "OIUY", False)
        DataGridView1.Rows.Add("3", "SDFGH", "LTDFGH", False)
        DataGridView1.Rows.Add("4", "ERJHGV", "CVHEYH", False)
        DataGridView1.Rows.Add("5", "AQSFGHKK", "TRDFHJH", False)
        DataGridView1.Rows.Add("6", "NQAAZTYI", "KITGHKG", False)
        DataGridView1.Rows.Add("7", "XBVSARY", "OTYHNC", False)
        DataGridView1.Rows.Add("8", "ACJKT", "PMLGESB", False)
        DataGridView1.Rows.Add("9", "FGHKL", "IUYTEYK", False)
        DataGridView1.Rows.Add("10", "WQAZR", "ERTYUVBD", False)
        DataGridView1.Rows.Add("11", "CKKTS", "EGCQA", False)

        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView1.AllowUserToAddRows = False

    End Sub

    ' button delete checked row
    Private Sub BtnDelete_Click(sender As Object, e As EventArgs) Handles BtnDelete.Click

        For i As Integer = DataGridView1.Rows.Count() - 1 To 0 Step -1
            Dim delete As Boolean
            delete = DataGridView1.Rows(i).Cells(3).Value

            ' if the checkbox cell is checked
            If delete = True Then
                Dim row As DataGridViewRow
                row = DataGridView1.Rows(i)
                DataGridView1.Rows.Remove(row)
            End If

        Next

    End Sub
End Class
      
///////////////OUTPUT:





vb remove datagridview checked row
VB.NET Remove DataGridView Checked Rows




VB.NET - How To Check If DataGridViewCheckBoxCell Is Checked In VB NET

vb datagridview check box


C# - How To Know If DataGridViewCheckBoxCell Is Checked In C#

                                                                                                                         

In This VB.NET Tutorial  We Will See How To Check If DataGridView CheckBox Cell Is Checked Or Not In VBNET Programming Language.


Project Source Code:

Public Class VB_DataGridView_CheckBoxCell_Checked

    Private Sub VB_DataGridView_CheckBoxCell_Checked_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ' add some row to datagridview
        ' true the checkBox Is checked
        ' false the checkBox Is Not checked
        Dim CheckBoxColumn As New DataGridViewCheckBoxColumn()
        CheckBoxColumn.HeaderText = "Check Box Column"
        DataGridView1.Columns.Add(CheckBoxColumn)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView1.AllowUserToAddRows = False

    End Sub

    Private Sub BtnCheckedCell_Click(sender As Object, e As EventArgs) Handles BtnCheckedCell.Click

        For i As Integer = 0 To DataGridView1.Rows.Count() - 1
            Dim c As Boolean
            c = DataGridView1.Rows(i).Cells(0).Value
            ' if the checkbox cell is checked
            If c = True Then
                MessageBox.Show("Checked")
                ' if not
            Else
                MessageBox.Show("Not Checked")
            End If
        Next

    End Sub
End Class
      
///////////////OUTPUT:





vb datagridview check box checked
vb datagridview checkbox cell checked




VB NET - How To Add CheckBox Column To DataGridView In VB.NET


DataGridView CheckBox Column In VB.NET

VB.NET - How To Add DataGridViewCheckBoxColumn To Datagridview Using VBNET

                                                                                                                         

In This VB.NET Tutorial  We Will See How To Add A Check Box Column To Datagridview 
In VBNET Programming Language.


Project Source Code:

Public Class VB_add_checkbox_to_datagridview

    Private Sub VB_add_checkbox_to_datagridview_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ' add some row to datagridview
        ' true the checkBox Is checked
        ' false the checkBox Is Not checked
        DataGridView1.Rows.Add(True)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(True)
        DataGridView1.Rows.Add(True)
        DataGridView1.Rows.Add(True)
        DataGridView1.Rows.Add(False)
        DataGridView1.Rows.Add(True)
        DataGridView1.Rows.Add(False)

        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView1.AllowUserToAddRows = False

        ''''''''''''''''''''''''''''''''''''

        Dim dgvCheck As New DataGridViewCheckBoxColumn()
        dgvCheck.HeaderText = "Check Box"
        DataGridView2.Columns.Add(dgvCheck)
        DataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView2.AllowUserToAddRows = False

        DataGridView2.Rows.Add(False)
        DataGridView2.Rows.Add(True)
        DataGridView2.Rows.Add(False)
        DataGridView2.Rows.Add(True)
        DataGridView2.Rows.Add(False)
        DataGridView2.Rows.Add(False)
        DataGridView2.Rows.Add(True)
        DataGridView2.Rows.Add(False)
        DataGridView2.Rows.Add(True)
        DataGridView2.Rows.Add(True)

    End Sub
End Class

///////////////OUTPUT:





VB DataGridView Check Box Column
VB DataGridView Check Box Column




C# - How To Display DataGridView Row Checked Cell In Another DataGridView Using C#

c# row from datagridview to another datagridview

C# - How To Show The DataGridView Row Checked Cell In Another DataGridView Using C#

____________________________________________________

In This C# Code We Will See How To Get Checked Row From 
Datagridview And Set Them To Another  Datagridview In  CSharp Programming Language .



Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Csharp_Transfere_Datagridview_Row_To_Another_Datagridview : Form
    {
        public Csharp_Transfere_Datagridview_Row_To_Another_Datagridview()
        {
            InitializeComponent();
        }

        private void Csharp_Transfere_Datagridview_Row_To_Another_Datagridview_Load(object sender, EventArgs e)
        {
            // create a text columns
            DataGridViewTextBoxColumn dgvcId = new DataGridViewTextBoxColumn();
            dgvcId.HeaderText = "Id";
            DataGridViewTextBoxColumn dgvcFn = new DataGridViewTextBoxColumn();
            dgvcFn.HeaderText = "First Name";
            DataGridViewTextBoxColumn dgvcLn = new DataGridViewTextBoxColumn();
            dgvcLn.HeaderText = "Last Name";

            // create checkbox column
            DataGridViewCheckBoxColumn dgvcCheckBox = new DataGridViewCheckBoxColumn();
            dgvcCheckBox.HeaderText = "Select";

            // add columns to datagridview
            dataGridView1.Columns.Add(dgvcId);
            dataGridView1.Columns.Add(dgvcFn);
            dataGridView1.Columns.Add(dgvcLn);
            dataGridView1.Columns.Add(dgvcCheckBox);

            // add some row to datagridview
            // true the checkBox Is checked
            // false the checkBox Is Not checked
            dataGridView1.Rows.Add("1", "DTYUI", "RTYUI", false);
            dataGridView1.Rows.Add("2", "KJHGF", "OIUY", false);
            dataGridView1.Rows.Add("3", "SDFGH", "LTDFGH", false);
            dataGridView1.Rows.Add("4", "ERJHGV", "CVHEYH", false);
            dataGridView1.Rows.Add("5", "AQSFGHKK", "TRDFHJH", false);
            dataGridView1.Rows.Add("6", "NQAAZTYI", "KITGHKG", false);
            dataGridView1.Rows.Add("7", "XBVSARY", "OTYHNC", false);
            dataGridView1.Rows.Add("8", "ACJKT", "PMLGESB", false);
            dataGridView1.Rows.Add("9", "FGHKL", "IUYTEYK", false);
            dataGridView1.Rows.Add("10", "WQAZR", "ERTYUVBD", false);
            dataGridView1.Rows.Add("11", "CKKTS", "EGCQA", false);
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.AllowUserToAddRows = false;

            // columns for dataGridView2
            DataGridViewTextBoxColumn dgvcId2 = new DataGridViewTextBoxColumn();
            dgvcId2.HeaderText = "Id";
            DataGridViewTextBoxColumn dgvcFn2 = new DataGridViewTextBoxColumn();
            dgvcFn2.HeaderText = "First Name";
            DataGridViewTextBoxColumn dgvcLn2 = new DataGridViewTextBoxColumn();
            dgvcLn2.HeaderText = "Last Name";
            dataGridView2.Columns.Add(dgvcId2);
            dataGridView2.Columns.Add(dgvcFn2);
            dataGridView2.Columns.Add(dgvcLn2);
            dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView2.AllowUserToAddRows = false;
        }

        private void btnFromGridToGrid_Click(object sender, EventArgs e)
        {
            // loop to check if the checkbox cell is checked
            for(int i = 0; i <= dataGridView1.Rows.Count-1; i++)
            {
                // rowAlreadyExist => if the row already exist on dataGridView2
                bool rowAlreadyExist = false;
                bool checkedCell = (bool)dataGridView1.Rows[i].Cells[3].Value;
                if(checkedCell == true)
                {
                    DataGridViewRow row = dataGridView1.Rows[i];

                    // the dataGridView2 have one row or more
                    if(dataGridView2.Rows.Count != 0)
                    {
                        // loop to see if the row already exist on dataGridView2
                        for(int j = 0; j <= dataGridView2.Rows.Count-1; j++)
                        {
                            if(row.Cells[0].Value.ToString() == dataGridView2.Rows[j].Cells[0].Value.ToString())
                            {
                                rowAlreadyExist = true;
                                break;
                            }
                        }

                        // add if the row ont exist on dataGridView2
                        if(rowAlreadyExist == false)
                        {
                            dataGridView2.Rows.Add(row.Cells[0].Value.ToString(),
                                                   row.Cells[1].Value.ToString(),
                                                   row.Cells[2].Value.ToString()
                                                   );
                        }
                    }

                    // add if the dataGridView2 have no row 
                    else
                    {
                        dataGridView2.Rows.Add(row.Cells[0].Value.ToString(),
                                                   row.Cells[1].Value.ToString(),
                                                   row.Cells[2].Value.ToString()
                                                   );
                    }
                }
            }
        }
    }
}

OutPut :
c# data from datagrid to another datagrid
C# data from Datagridview to another Datagridview




C# - How To Delete DataGridView Row Checked Cell In C#

c# delete datagridview checked row

C# - How To Remove The Checked Row From Datagridview Using C#

____________________________________________________

In This C# Code We Will See How To Delete The 
Datagridview Row With CheckBox Checked In  CSharp  Programming Language .



Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Csharp_delete_datagridview_checked_checkbox_cell : Form
    {
        public Csharp_delete_datagridview_checked_checkbox_cell()
        {
            InitializeComponent();
        }

        private void Csharp_delete_datagridview_checked_checkbox_cell_Load(object sender, EventArgs e)
        {
            // create a text columns
            DataGridViewTextBoxColumn dgvcId = new DataGridViewTextBoxColumn();
            dgvcId.HeaderText = "Id";
            DataGridViewTextBoxColumn dgvcFn = new DataGridViewTextBoxColumn();
            dgvcFn.HeaderText = "First Name";
            DataGridViewTextBoxColumn dgvcLn = new DataGridViewTextBoxColumn();
            dgvcLn.HeaderText = "Last Name";

            // create checkbox column
            DataGridViewCheckBoxColumn dgvcCheckBox = new DataGridViewCheckBoxColumn();
            dgvcCheckBox.HeaderText = "Delete";

            // add columns to datagridview
            dataGridView1.Columns.Add(dgvcId);
            dataGridView1.Columns.Add(dgvcFn);
            dataGridView1.Columns.Add(dgvcLn);
            dataGridView1.Columns.Add(dgvcCheckBox);

            // add some row to datagridview
            // true the checkBox Is checked
            // false the checkBox Is Not checked
            dataGridView1.Rows.Add("1","DTYUI","RTYUI",false);
            dataGridView1.Rows.Add("2", "KJHGF", "OIUY", false);
            dataGridView1.Rows.Add("3", "SDFGH", "LTDFGH", false);
            dataGridView1.Rows.Add("4", "ERJHGV", "CVHEYH", false);
            dataGridView1.Rows.Add("5", "AQSFGHKK", "TRDFHJH", false);
            dataGridView1.Rows.Add("6", "NQAAZTYI", "KITGHKG", false);
            dataGridView1.Rows.Add("7", "XBVSARY", "OTYHNC", false);
            dataGridView1.Rows.Add("8", "ACJKT", "PMLGESB", false);
            dataGridView1.Rows.Add("9", "FGHKL", "IUYTEYK", false);
            dataGridView1.Rows.Add("10", "WQAZR", "ERTYUVBD", false);
            dataGridView1.Rows.Add("11", "CKKTS", "EGCQA", false);
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.AllowUserToAddRows = false;
        }

        // button delete checked row
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            for(int i = dataGridView1.Rows.Count-1; i >= 0; i--)
            {
                bool delete = (bool)dataGridView1.Rows[i].Cells[3].Value;

                // if the checkbox cell is checked

                if(delete == true)
                {
                    DataGridViewRow rowToRemove = dataGridView1.Rows[i];

                    dataGridView1.Rows.Remove(rowToRemove);
                }
            }
        }
    }
}



OutPut :
c# remove datagridview checked row
c# remove datagridview checked row