日期:2014-05-18  浏览次数:20886 次

如何设置datagridview某一个单元格的边框样式
我只知道 如何设置 所有单元格的样式的方法: 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不能点击,这功能如何实现?
谢谢!!!

------解决方案--------------------
你换其他第三方控件可以实现你的需求
如spread控件
------解决方案--------------------
自已实现这个功能比较麻烦,还是到网上下载控件用吧!不过如果你有时间也可以慢慢研究!
------解决方案--------------------
帮顶!
------解决方案--------------------
还得学习一下
------解决方案--------------------
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;

}
}

 

------解决方案--------------------
if (e.ColumnIndex == 0)//所在列的索引
{
DataGridViewCellStyle newCellStyle = new DataGridViewCellStyle();
 

dataGridView1.Rows[e.RowIndex].DefaultCellStyle = newCellStyle;