现在的位置: 首页 > 综合 > 正文

c# 实现datagridview 用回车向右移动,到头换行,支持编辑模式

2018年02月11日 ⁄ 综合 ⁄ 共 769字 ⁄ 字号 评论关闭
        /// <summary>
      /// 全局变量: 判断dataGridView 是否处于编辑状态
      /// </summary>
       private bool m_isdataGridViewBegingEdit = false;
 
        protected override bool
ProcessCmdKey(ref Message msg, Keys keyData)

        {
            if (keyData == Keys.Enter && (m_isdataGridViewBegingEdit == true || this.dataGridView1.Focused == true))
            {
                System.Windows.Forms.SendKeys.Send("{tab}");
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
 
        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            m_isdataGridViewBegingEdit = true;
        }
 
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            m_isdataGridViewBegingEdit = false;
        }

抱歉!评论已关闭.