zoukankan      html  css  js  c++  java
  • datagridview相关

    在datagridview中常常需要的一个需求就是,用户敲击enter键后编辑列自动跳到后面一列,而不是下一行(默认)。在datagridview的keydown事件中是捕捉不到这个事件的。不过可以通过重写整个窗体的按键消息来达到目的:

            protected override bool ProcessCmdKey(ref   System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
            {
                if (msg.WParam.ToInt32() == (int)Keys.Enter)
                {
                    SendKeys.Send("{Tab}");
                    return true;
                }
                  return base.ProcessCmdKey(ref   msg, keyData);
             }
    

    动态添加行数据时,将当前焦点定位到新加的行且该行可见:

    int index = 1;  //需要定位的行
    
    gridView.Rows[index].Selected = true; 
    
    //令选中的行可见,否则有可能虽然选中了但是不可见
    //前提是当行选中,而不是多行选中
    gridView.FirstDisplayedScrollingRowIndex =gridViewProgram.SelectedRows[0].Index;
    

      

    不管是编辑还是非编辑状态下获得单元格的值

     DataGridViewCell dataGridViewCell = gridView.Rows[RowIndex].Cells[ColumnIndex];
    
     string cellValue = dataGridViewCell.EditedFormattedValue.ToString();
    

      

  • 相关阅读:
    echarts-五分钟的教程
    vue中的路由
    2x or 3X的图
    background-size cover和contain的用法详解
    吃转基因有害?科普这么多年咋还有人信!
    基于UDP协议的Socket通信
    基于TCP协议Socket通信
    echarts地图
    Ehcache缓存实例
    Tomcat配置绝对路径
  • 原文地址:https://www.cnblogs.com/qianlifeng/p/1777543.html
Copyright © 2011-2022 走看看