且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在列表框中选择文本框项不会更改列表框的选定项

更新时间:2023-11-28 20:05:22

我们使用以下样式设置一个 PreviewGotKeyboardFocus,它处理 TextBox 控件和 ComboBoxes 等的所有事件:

We use the following style to set a PreviewGotKeyboardFocus which handles all events of TextBox control and ComboBoxes and such:

    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <EventSetter Event="PreviewGotKeyboardFocus" Handler="SelectCurrentItem"/>
        </Style>
    </ListView.ItemContainerStyle>

然后我们选择后面代码中的行:

And then we select the row in code behind:

    protected void SelectCurrentItem(object sender, KeyboardFocusChangedEventArgs e)
    {
        ListViewItem item = (ListViewItem) sender;
        item.IsSelected = true;
    }