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
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.
As discussed in OP comments:
dataGridView.ReadOnly = true;
Inside any DataGridView events you are handling, check the ReadOnly property and do not do anything inside the event if true.
I looked at another option of iterating through rows and columns and disabling each of them, but Enabled is not a property of the row or column object. Iterating through a large number of items would be slow, anyway.
T. Fabre answer didn't work for me. In my case, I have buttons and editable checkboxes for each row of my datagrid, so they won't be deactivated even if the DataGrid is in ReadOnly. However, what did work for me (without disabling the scroll) is disabling each row like in this example:
<Style TargetType="{x:Type DataGridRow}" x:Key="MyDataGridRowStyle">
<Style.Setters>
<Setter Property="IsEnabled" Value="False"/>
</Style.Setters>
</Style>
And then in the DataGrid:
<DataGrid ... RowStyle="{StaticResource MyDataGridRowStyle}">
Hope that helps (sorry if only posted the XAML solution)!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With