DataGridView中:如何设置在编辑模式下的电池? [英] Datagridview: How to set a cell in editing mode?

查看:118
本文介绍了DataGridView中:如何设置在编辑模式下的电池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过编程设置编辑模式的单元格。我知道,设定该单元格为CurrentCell,然后调用方法BeginEdit(布尔),它应该发生,但对我来说,它没有。

I need to programmatically set a cell in editing mode. I know that setting that cell as CurrentCell and then call the method BeginEdit(bool), it should happen, but in my case, it doesn't.

我真的很想说,我DGV几个栏目,用户只能选择,还可以编辑的第2位。其他列已经只读的,但用户可以选择他们,这是我不想要的东西。

I really want that, with my DGV with several columns, the user can ONLY select and also edit the first two. The other columns are already read-only, but the user can select them, and that is what I don't want.

所以,我在想,告诉用户TAB每次它已经写完的单元格,然后选择第二个单元格,然后再选项卡,并选中,并开始修改下一行的第一个单元格...

So I was thinking, tell the user to TAB everytime it has finished writing on the cell, then select the second cell, then tab again and it select and begin edit the next row's first cell...

我怎样才能做到这一点?

How can I do this?

推荐答案

设置 CurrentCell ,然后调用 BeginEdit(真)很适合我。

Setting the CurrentCell and then calling BeginEdit(true) works well for me.

下面code显示了事件处理程序的的KeyDown 事件设置一个单元格可编辑。

The following code shows an eventHandler for the KeyDown event that sets a cell to be editable.

我的例子只实现所需的关键preSS覆盖之一,但在理论上别人应该是一样的。 (我总是设置[0] [0]电池是可编辑的,但是任何其他细胞应该工作)

My example only implements one of the required key press overrides but in theory the others should work the same. (and I'm always setting the [0][0] cell to be editable but any other cell should work)

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

如果你还没有找到它previously的<一个href="https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCwQFjAA&url=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F5%2F6%2F4%2F5646742C-3EB7-48F7-BFB3-CC295D618CF9%2FDataGridView%2520FAQ.doc&ei=FFgTUrW2HYfChAeMnYDwCg&usg=AFQjCNHE0C79uGnD14VrXWm07wvfhzPWUQ&bvm=bv.50952593,d.ZG4">DataGridView常见问题解答是一个很好的资源,为DataGridView控件,它涵盖了大部分内容,你可能想要做对照写的项目经理。

If you haven't found it previously, the DataGridView FAQ is a great resource, written by the program manager for the DataGridView control, which covers most of what you could want to do with the control.

这篇关于DataGridView中:如何设置在编辑模式下的电池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆