简体   繁体   中英

DataGridComboBoxColumn opens after 2 mouse clicks

I have a datagrid and it has DataGridComboBoxColumn like below. When i open datagrid, 2 mouse clicks show the combox. How to show combobox when datagrid is loaded without click.

<DataGrid  x:Name="customLoadCaseGrid" 
              ItemsSource="{Binding Source={StaticResource weightItemCollection}}"
              CanUserSortColumns="False"  SelectionMode="Single"  AutoGenerateColumns="False"  Margin="5,5,5,5"
              CanUserDeleteRows="False"
              Grid.Row="1" Grid.Column="0" Grid.RowSpan="19" Grid.ColumnSpan="20"  
              CellEditEnding="DataGridCellEditEnding" PreviewKeyDown="DatagridPreviewKeyDown" 
              BeginningEdit="DatagridBeginningEdit" BorderThickness="2" >

<DataGrid.Columns>

 <DataGridComboBoxColumn Header="{lex:LocText Key=fsm_type, Dict=language, Assembly=StabilityGui}" SortMemberPath="FsmTypes" Width="1*" Visibility="Visible"> 
                <DataGridComboBoxColumn.ElementStyle>
                    <Style>
                        <Setter Property="ComboBox.ItemsSource" Value="{Binding Path=FsmTypes}" />
                    </Style>
                </DataGridComboBoxColumn.ElementStyle>
                <DataGridComboBoxColumn.EditingElementStyle>
                    <Style>
                        <Setter Property="ComboBox.ItemsSource" Value="{Binding Path=FsmTypes}" />
                    </Style>
                </DataGridComboBoxColumn.EditingElementStyle>
            </DataGridComboBoxColumn>
        </DataGrid.Columns>
    </DataGrid>

If you want to display a ComboBox in the CellTemplate , you should replace the DataGridComboBoxColumn with a DataGridTemplateColumn :

<DataGrid ...>
    <DataGrid.Resources>
        <DataTemplate x:Key="template">
            <ComboBox ItemsSource="{Binding Path=FsmTypes, RelativeSource={RelativeSource AncestorType=Window}}" />
        </DataTemplate>
    </DataGrid.Resources>
    <DataGrid.Columns>
        <DataGridTemplateColumn ... CellTemplate="{StaticResource template}" CellEditingTemplate="{StaticResource template}" />
        ...
    </DataGrid.Columns>
</DataGrid>

You can open one of the ComboBoxes by setting the IsDropDownOpen property to true . You cannot have more than one ComboBox open at the same time though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM