zoukankan      html  css  js  c++  java
  • dataGridView 去除默认选择

    dataGirdView 默认加载数据后,会选择第一行的第一个可见单元格。而有的时候我们不需要这样,已达到让容易点击一个后,在进行操作。

    我们可以用如下的代码实现:

    dataGridView1.Rows[0].Selected = false;
    this.dataGridView1.TabStop = false;
    dataGridView1.Rows[0].Selected = false;
    this.dataGridView1.CurrentCell = null;
    dataGridView1.ClearSelection();

    但是有个注意点:

    不能写在窗体的初始化函数里面写。。
    只能在 Load里面写。。

    public Form1()
    {
    InitializeComponent();
    dataGridView1.Rows[0].Selected = false;//无效
    //this.dataGridView1.TabStop = false;//无效
    //dataGridView1.Rows[0].Selected = false;//无效
    //this.dataGridView1.CurrentCell = null;//无效
    //dataGridView1.ClearSelection();//无效
    //dataGridView1.Rows[0].Selected = false; //无效
    }
    private void Form1_Load(object sender, EventArgs e)
    {
    dataGridView1.Rows[0].Selected = false;
    //this.dataGridView1.TabStop = false;
    //dataGridView1.Rows[0].Selected = false;
    //this.dataGridView1.CurrentCell = null;
    //dataGridView1.ClearSelection();
    }

    当然也可以放在按钮下,神马的~

  • 相关阅读:
    logback配置和使用
    安装多个jdk导致eclipse打不开问题
    Spring事务管理
    使用JavaConfig配置SpringMVC
    Spring pom.xml配置
    Maven私服搭建(Nexus Repository Manager 3)
    Maven多环境配置
    Maven多模块构建实例
    Maven依赖机制
    Maven安装与配置
  • 原文地址:https://www.cnblogs.com/lingfengchencn/p/2551065.html
Copyright © 2011-2022 走看看