我只知道 如何设置 所有单元格的样式的方法: DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single我在datagridview中加入一个button列,点击它 就会设置该列第2个一个单元格的样式,如何做到呢?
    private void dataviewAccountList_CellContentClick(object sender, DataGridViewCellEventArgs e)
    //点击投资者列表中 内容时发生
    {
            //如果"编辑"列按钮被点击
        if (dataviewAccountList.Columns[e.ColumnIndex].Name == "btnEdit")  //判断是否单击了“编辑”列
        {
            dataviewAccountList[1, e.RowIndex].Style = DataGridViewCellBorderStyle.Raised;//报错了!!!
        }
     }还有一个小问题:在我点击某一行的btnEdit后,要想使其他行的btnEdit不能点击,这功能如何实现?
谢谢!!!

解决方案 »

  1.   

    你换其他第三方控件可以实现你的需求
    如spread控件
      

  2.   

    private void datagridview1_CellContentClick(object sender, DataGridViewCellEventArgs e)
      {
      if (e.RowIndex > -1)
      {
      if (e.ColumnIndex == 0)//所在列的索引
      {
      DataGridViewCellStyle newCellStyle = new DataGridViewCellStyle();
        dataGridView1.Rows[e.RowIndex].DefaultCellStyle = newCellStyle;  }
      }
      } 
     
      

  3.   

    if (e.ColumnIndex == 0)//所在列的索引
      {
      DataGridViewCellStyle newCellStyle = new DataGridViewCellStyle();
         dataGridView1.Rows[e.RowIndex].DefaultCellStyle = newCellStyle;
      

  4.   

    如果是e.ColumnIndex==0那么所有行都会被设置,就算添加&&e.RowIndex==0都没有用