You must Sign In to post a response.
  • Category: .NET

    HOw to get value from datagridviewcheckboxcolumn?

    Are you looking for a way to get value from datagridviewcheckboxcolumn then read this thread to know how to get it

    I have a datagridview(dgv) , in which i adding first column as dgvcheckboxcolumn and i am able to extract value of second column whose checkboxcell checked. but i am getting a different type of error that is "when i check 1st row checkbox its value not retrived but when i check any other row check box previously checked row value retrived" , but i want to extract instant value , i.e if i checked 1st rows's checkbox i want 1st rows 2nd column value.

    here is my code i know something simple mistake i did but cant traced out ,

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

    List<DataGridViewRow> rows_with_checked_column = new List<DataGridViewRow>();

    foreach (DataGridViewRow row in dataGridView1.Rows)
    if (Convert.ToBoolean(row.Cells[SerialNo.Name].Value) == true)
    data = row.Cells[1].Value.ToString();
    row.Cells[SerialNo.Name].Value = false;

    ifile.IniWriteValue("Config Section", "INDENT_NO", data);
    txtindentcode.Text = data;
    txtfromstore.Text = fm;
    txttostore.Text = to;
  • #763461
    You can try using the CellValueChanged event of the grid
    it will help you to get checked row values, see below snippet
    void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    if (e.ColumnIndex == 0)
    bool isChecked = (Boolean) dataGridView1[0, e.RowIndex].FormattedValue;

    if (isChecked)
    dataGridView1[1, e.RowIndex].Value = true;

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763464
    In value event same result given as i explained,
    now i can able to retrive real values,
    i found solution to this problem by following line,
    data = dataGridView1.Rows[index].Cells[1].Value.ToString();
    "if (Convert.ToBoolean(row.Cells[SerialNo.Name].Value) == true)" this condition false for thirst check after that it gives proper values , whts wrong with this code?

  • #763471

    Hello Priyanka Barwad,

    Try this code. which is worked for me.

    if (StockView.CurrentCell is DataGridViewCheckBoxCell)
    //Below code for getting checked value of checkbox
    bool isChecked = (bool)StockView[e.ColumnIndex, e.RowIndex].EditedFormattedValue;

    // Checking value of checkbox
    if (isChecked == true)
    MessageBox.Show(StockView[e.ColumnIndex, e.RowIndex].Value.ToString());

    Hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

Sign In to post your comments