2

我有一个,当我不希望用户更改任何内容时DataGrid,我当前设置为该位置,然后我有一个按钮供用户单击以允许修改,然后更改为 falseReadOnlyIsReadOnly

但现在的问题是,当 时DataGrid.IsReadOnly = true,滚动被禁用。如何使 DataGridIsReadOnly=true或类似的并且仍然能够滚动DataGrid

数据网格样式:

<DataGrid.Style>
  <Style TargetType="{x:Type DataGrid}">
    <Style.Triggers>
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding ReadOnly}" Value="True"/>
          <Condition Binding="{Binding Reordering}" Value="False"/>
        </MultiDataTrigger.Conditions>
        <MultiDataTrigger.Setters>
          <Setter Property="IsReadOnly" Value="True" />
          <Setter Property="IsHitTestVisible" Value="False" />
          <Setter Property="Foreground" Value="Gray" />
        </MultiDataTrigger.Setters>
      </MultiDataTrigger>
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding ReadOnly}" Value="True"/>
          <Condition Binding="{Binding Reordering}" Value="True"/>
        </MultiDataTrigger.Conditions>
        <MultiDataTrigger.Setters>
          <Setter Property="IsHitTestVisible" Value="False" />
          <Setter Property="IsReadOnly" Value="True" />
        </MultiDataTrigger.Setters>
      </MultiDataTrigger>
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding ReadOnly}" Value="False"/>
        </MultiDataTrigger.Conditions>
        <MultiDataTrigger.Setters>
          <Setter Property="IsHitTestVisible" Value="True" />
          <Setter Property="IsReadOnly" Value="False" />
        </MultiDataTrigger.Setters>
      </MultiDataTrigger>
    </Style.Triggers>
  </Style>
</DataGrid.Style>
4

1 回答 1

0

你有没有试过这个:

dataGridView1.ReadOnly = true;
void dataGridView1_DoubleClick(object sender, EventArgs e)
{
     if (dataGridView1.ReadOnly == true)
          return;

     // .. whatever code you have in your handler...
}

禁用 DataGridView 除了滚动

于 2012-11-01T18:33:35.810 回答