【问题标题】:How to enter edit mode in next cell when I hit "Enter", instead of just focus on the next cell?当我点击“Enter”时如何在下一个单元格中进入编辑模式,而不是只关注下一个单元格?
【发布时间】:2013-12-11 22:47:10
【问题描述】:

这是我的代码:

       <DataGridTemplateColumn  Header="xxx" Width="*" >
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox IsReadOnly="{Binding VialPosition,Converter={StaticResource EditableCondition}}"        
                                 Background="{Binding ExtractionIDBackgroundColor, Converter={StaticResource ColorConvert}}" 
                                 TextAlignment="Center" Height="30" Width="375" 
                                 Text="{Binding ExtractionId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

当我点击“Enter”时如何在下一个单元格中进入编辑模式,而不是只关注下一个单元格?

【问题讨论】:

  • 答案对你有用吗?

标签: c# wpf


【解决方案1】:

要做到这一点,您需要对 CellStyle 进行一些修改,并像 BeginEdit(); 那样操作事件

这里有一些很好的例子来说明如何做到这一点,我已经使用过它们并且效果很好。

这些示例包含您需要的所有代码。您只需要进行一些修改以适应您的软件。

希望对你有帮助

【讨论】:

  • 嗨,维尼修斯,谢谢您的回复。它确实可以很好地满足我上面提到的需求。然而,还有另一种情况。我已将 IsReadOnly 和 Background 绑定到转换器,以禁用第一行。那么,无论如何我可以禁用第一行单元格并按照我上面要求的方式编辑其余单元格吗?
  • 首先,如果有帮助,你能接受吗? (谢谢)其次,我相信您必须为您期望从细胞中获得的每种行为创建不同的样式。例如,创建一个禁用一行的样式并将其赋予第一个,然后应用另一种样式(执行上述功能)。
【解决方案2】:

使用方法BeginEdit()。此信息的链接是HERE

【讨论】:

  • 只有链接的答案通常是poor practice。尝试充实与 OP 的问题相关的想法
  • @paqogomez OP 没有显示任何研究。我向他们提供了要使用的方法和要阅读的文档。他们不应该用勺子喂。
【解决方案3】:

这样的事情会起作用:

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        e.Handled = true;
        DataGridViewCell cell = dataGridView1.Rows[0].Cells[0];
        dataGridView1.CurrentCell = cell;
        dataGridView1.BeginEdit(true);               
    }
}

你可能会发现WPF tips and tricks编辑也有一些用处

【讨论】:

    猜你喜欢
    • 2016-10-27
    • 2014-12-05
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 2018-09-29
    相关资源
    最近更新 更多