Search code examples
c#datagridviewdisabled-control

Disable DataGridView except the scroll


How I can configure a datagridview so that the user can only move through the rows and use the scroll, and nothing else... If I disable the grid not allow me to use the scroll


Solution

  • Set your datagridview to read-only, this will disable any edits.

    dataGridView1.ReadOnly = true;
    

    And inside your handlers, do :

    void dataGridView1_DoubleClick(object sender, EventArgs e)
    {
         if (dataGridView1.ReadOnly == true)
              return;
    
         // .. whatever code you have in your handler...
    }
    

    Even if the user double-clicks on the grid, nothing will happen.