首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么取消dataGridView中PreviewKeyDown事件里回车换行

2013-03-27 
如何取消dataGridView中PreviewKeyDown事件里回车换行我添加了一个PreviewKeyDown事件,想按下回车后只取出

如何取消dataGridView中PreviewKeyDown事件里回车换行
我添加了一个PreviewKeyDown事件,想按下回车后只取出单元格中的内容后保持在原行而不换行
怎么写?
[解决办法]
这里可以采用投机取巧的办法,按回车他往下,那你给他发送一个向上的指令就可以了


 private void dataGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (sender != null)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    DataGridView drvc = sender as DataGridView;
                    if (drvc != null)
                    {
                        if (drvc.SelectedCells != null)
                        {
                            MessageBox.Show(drvc.SelectedCells[0].Value.ToString());
                            SendKeys.Send("{Up}");
                        }
                    }
                }
            }
           
        }

热点排行