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

Winform中的Datagridview的第1,2,3,4列为Checkbox,如何根据第1列的值改变第2,3,4例的值?
Winform中的Datagridview的第1,2,3,4列为Checkbox

如何在改变第1列的Checkbox时,把第2,3,4列的checkbox值改成和第一列一样?

我在CellContentClick事件中添加如下代码:


  private void dgvLevel_CellContentClick(object sender, DataGridViewCellEventArgs e)
  {
  int intState = Convert.ToInt32(dgvLevel.Rows[e.RowIndex].Cells[0].Value);
  dgvLevel.Rows[e.RowIndex].Cells[1].Value = intState;
  dgvLevel.Rows[e.RowIndex].Cells[2].Value = intState;
  dgvLevel.Rows[e.RowIndex].Cells[3].Value = intState;
  }

没有任何效果,通过MessageBox来显示intState,总是显示1,而不是根据是否选中显示

------解决方案--------------------
建议楼主用javascript来实现。我以前做过
------解决方案--------------------
哇,试了一下,竟然找不到。郁闷啊,试过以下方法。。
C# code

  DataGridViewCheckBoxCell cell = new DataGridViewCheckBoxCell();
        public test()
        {
            InitializeComponent();
            cell.FalseValue = 0;
            cell.TrueValue = 1;
            
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowindex = e.RowIndex;
            int columnindex = e.ColumnIndex;
            if (columnindex == 0)
            {
                
                cell = (DataGridViewCheckBoxCell)this.dataGridView1.Rows[rowindex].Cells[0];
                
                object a = cell.Value;
                a = cell.FormattedValue;
                a = cell.Tag;
                
               DataGridViewElementStates state =this.dataGridView1.Rows[rowindex].Cells[0].State;              
            }

        }

------解决方案--------------------
应该让微软提供CellValueChanged事件处理。