-4

I want that when I check the checkbox in the datagrid view my button that is disabled at the beginning will be activated after I want the selected lines to be inserted in a table.

halfer
  • 19,824
  • 17
  • 99
  • 186
maroua
  • 1
  • 3

1 Answers1

-1

I don't know if you are using the standard DataGridView from .NET but I will assume you do. Also the assumption goes that your checkbox is not binded to a model. Subscribe to the dataGridView_CellClick event and handle you case and handle there the business.

private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 0/*myColumn*/ && e.RowIndex == 0 /*myRow*/)
        {
            myButton.Enable = true;
            //do other business
        } 

    }

Also the dataGridView_CellContentClick event can be used depending on what you need.

Diizzy
  • 534
  • 4
  • 12
  • yes. Your column in which you hold the checkbox control. Maybe the dataGridView_CellContentClick is more suitable for your case. The CellClick event will be fired even if the use will not click in the checkbox but the click is in the cell. – Diizzy Mar 14 '17 at 10:41
  • Sorry for the inconvenience I want the user to just select a line in the datagridview – maroua Mar 14 '17 at 10:47
  • Your description says otherwise "I want that when I check the checkbox in the datagrid view my button that is disabled at the beginning will be activated ". Plus you can use the dataGridView.SelectedRows to get the collection of selected rows. – Diizzy Mar 14 '17 at 10:55
  • En tous cas merci :) – maroua Mar 14 '17 at 10:57
  • I still don't understand why you downvoted my answer. :) – Diizzy Mar 14 '17 at 10:59
  • No I have not voted I'm debuting in this site I know not voted – maroua Mar 14 '17 at 11:01