首页 新闻 会员 周边

WPF MVVM使用dev中的GridControl设置默认不选择行时绑定SelectionChanged时报错

0
悬赏园豆:100 [已解决问题] 解决于 2024-01-10 16:56

今天突然发现的问题,询问一下大佬们有遇到相关的情况没,
GridControl设置AllowInitiallyFocusedRow=false后与事件的绑定有问题了,这两去掉任意一个就正常,不能共存。

            <dxg:GridControl
                Height="300"
                AllowInitiallyFocusedRow="False"
                ClipboardCopyMode="ExcludeHeader"
                CopyingToClipboard="GridControl_CopyingToClipboard"
                FontSize="14"
                ItemsSource="{Binding Iv_List, Mode=OneWay}"
                SelectedItem="{Binding Iv_Info, Mode=OneWay}"
                SelectionMode="Row">
                <b:Interaction.Triggers>
                    <b:EventTrigger EventName="SelectionChanged">
                        <prism:InvokeCommandAction Command="{Binding DataContext.FocusableIvChangedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dxg:GridControl}}}" CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType={x:Type dxg:GridControl}, Mode=FindAncestor}}" />
                    </b:EventTrigger>
                </b:Interaction.Triggers>
                <dxg:GridControl.TotalSummary>
                    <dxg:GridSummaryItem Alignment="Left" SummaryType="Count" />
                </dxg:GridControl.TotalSummary>
                <dxg:GridControl.View>
                    <dxg:TableView
                        AllowColumnFiltering="True"
                        AllowEditing="True"
                        AllowHorizontalScrollingVirtualization="True"
                        AllowPerPixelScrolling="True"
                        NavigationStyle="Cell"
                        ShowAutoFilterRow="False"
                        ShowFixedTotalSummary="True"
                        ShowGroupPanel="False">
                        <dxg:TableView.ColumnHeaderStyle>
                            <Style TargetType="dxg:BaseGridHeader">
                                <Setter Property="Height" Value="28" />
                            </Style>
                        </dxg:TableView.ColumnHeaderStyle>
                        <dxg:TableView.FormatConditions>
                            <dxg:FormatCondition
                                ApplyToRow="true"
                                Expression="[ColorEdit]='1'"
                                FieldName="ColorEdit">
                                <dx:Format Background="#FF81D966" />
                            </dxg:FormatCondition>
                        </dxg:TableView.FormatConditions>
                        <!--<dxg:TableView.CellStyle>
                            <Style TargetType="DataGridCell">
                                <Setter Property="IsHitTestVisible" Value="False" />
                            </Style>
                        </dxg:TableView.CellStyle>-->
                    </dxg:TableView>
                </dxg:GridControl.View>
                <dxg:GridControl.Columns>
                    <dxg:GridColumn
                        Width="*"
                        FieldName="CLIV_SHIP_DISALLOW_AMT"
                        FilterPopupMode="CheckedList"
                        Header="自费">
                        <dxg:GridColumn.EditSettings>
                            <dxe:TextEditSettings
                                Mask="f2"
                                MaskType="Numeric"
                                MaskUseAsDisplayFormat="True" />
                        </dxg:GridColumn.EditSettings>
                    </dxg:GridColumn>
                </dxg:GridControl.Columns>
            </dxg:GridControl>


湛花花的主页 湛花花 | 初学一级 | 园豆:57
提问于:2024-01-10 16:41
< >
分享
最佳答案
0

llowInitiallyFocusedRow属性设置为false后绑定SelectionChanged事件会报错。这可能是因为在设置AllowInitiallyFocusedRow为false后,焦点不再自动定位到第一行,而是保持在原来的位置。因此,当你尝试绑定SelectionChanged事件时,可能会出现索引超出范围的错误,因为没有选中任何行。

为了解决这个问题,你可以在绑定SelectionChanged事件之前,手动设置一行为选中状态,以确保事件能够正常触发

修改事件接受类型,

湛花花 | 初学一级 |园豆:57 | 2024-01-10 16:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册